Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nativescript-community/appurl

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nativescript-community/appurl

Register custom URLs for your NativeScript app

  • 1.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28
increased by40%
Maintainers
7
Weekly downloads
 
Created
Source

NativeScript URL Handler Plugin apple android

this is a direct fork/rewrite of nativescript-urlhandler by Martin Reinhardt It did not seem to be maintained anymore and was not working as expected

Usage

Just add App links to your app, see iOS and Android instructions below, and register a handler for the URL data.

See this example for Angular:

import { Component, OnInit } from "@angular/core";
import { handleOpenURL, AppURL } from '@nativescript-community/appurl';

@Component({
  selector: "gr-main",
  template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent {
    constructor() {
    } 
    
    ngOnInit(){
        handleOpenURL((appURL: AppURL) => {
            console.log('Got the following appURL', appURL);
        });
     }
}

And for pure NativeScript:

var handleOpenURL = require("@nativescript-community/appurl").handleOpenURL;

handleOpenURL(function(appURL) {
  console.log('Got the following appURL', appURL);
});

Or as TypeScript:

import { handleOpenURL, AppURL } from '@nativescript-community/appurl';

handleOpenURL((appURL: AppURL) => {
  console.log('Got the following appURL', appURL);
});

Note: see demo app for sample usage. Start by adding handleOpenURL in app main!

Installation

$ tns plugin add @nativescript-community/appurl

Or if you want to use the development version (nightly build), which maybe not stable!:

$ tns plugin add @nativescript-community/appurl@next

Android

Replace myapp with your desired scheme and set launchMode to singleTask

<activity android:name="com.tns.NativeScriptActivity" ... android:launchMode="singleTask"...>
        ...
    <intent-filter>
    <data android:scheme="myapp" /> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    </intent-filter>

For example:

<activity android:name="com.tns.NativeScriptApplication" android:label="@string/app_name" android:launchMode="singleTask">
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="myapp" android:host="__PACKAGE__" />
  </intent-filter>
</activity>

The android:launchMode="singleTask" tells the Android operating system to launch the app with a new instance of the activity, or use an existing one. Without this your app will launch multiple instances of itself which is no good.

iOS

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.myapp</string>
    </dict>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>myapp</string>
        </array>
    </dict>
</array>

FAQ

Callback handling

The "handleOpenURL" callback must be called before application initialization, otherwise you'll see this error in the console:

    No callback provided. Please ensure that you called "handleOpenURL" during application init!

Webpack

TypeScript Config

If your Webpack Build is failing, try adapting your tsconfig to this:

    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
        "lib": [
            "es6",
            "dom",
            "es2015.iterable"
        ],
        "baseUrl": ".",
        "paths": {
            "*": [
                "./node_modules/@nativescript/core/*",
                "./node_modules/*"
            ]
        }
    },
    "exclude": [
        "node_modules",
        "platforms",
        "**/*.aot.ts"
    ]

Keywords

FAQs

Package last updated on 09 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc