1.3.0 • Published 5 years ago

nativescript-urlhandler v1.3.0

Weekly downloads
922
License
MIT
Repository
github
Last release
5 years ago

NativeScript URL Handler Plugin apple android

Greenkeeper badge Build Status Donate with Bitcoin

npm versionMaintainability

NPM

Feel free to donate

Bitcoin

Also via greenaddress

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-urlhandler';

@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-urlhandler").handleOpenURL;

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

Or as TypeScript:

import { handleOpenURL, AppURL } from 'nativescript-urlhandler';

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-urlhandler

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

$ tns plugin add nativescript-urlhandler@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/tns-core-modules/*",
                "./node_modules/*"
            ]
        }
    },
    "exclude": [
        "node_modules",
        "platforms",
        "**/*.aot.ts"
    ]
1.3.0-master-31

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2-master-29

6 years ago

1.2.2-develop-94

6 years ago

1.2.2

6 years ago

1.2.1-develop-93

6 years ago

1.2.1-develop-91

6 years ago

1.2.1

7 years ago

1.2.0-develop-81

7 years ago

1.2.0-develop-78

7 years ago

1.2.0-master-28

7 years ago

1.2.0-develop-77

7 years ago

1.2.0

7 years ago

1.1.1-develop-76

7 years ago

1.1.1-develop-75

7 years ago

1.1.1-develop-73

7 years ago

1.1.1-master-27

7 years ago

1.1.1-develop-71

7 years ago

1.1.1

7 years ago

1.1.0-develop-70

7 years ago

1.1.0-develop-69

7 years ago

1.1.0-develop-68

7 years ago

1.1.0-develop-67

7 years ago

1.1.0-develop-65

7 years ago

1.1.0-develop-63

7 years ago

1.1.0-develop-61

7 years ago

1.1.0-master-23

7 years ago

1.0.0-develop-60

7 years ago

1.1.0

7 years ago

1.0.0-develop-59

7 years ago

1.0.0-develop-58

7 years ago

1.0.0-develop-55

7 years ago

1.0.0-develop-1

7 years ago

1.0.0-develop-54

7 years ago

1.0.0-develop-53

7 years ago

1.0.0-develop-51

7 years ago

1.0.0-develop-50

7 years ago

1.0.0-develop-49

7 years ago

1.0.0-develop-48

7 years ago

1.0.0

7 years ago

0.5.1-develop-43

7 years ago

0.5.1-develop-42

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0-develop-29

7 years ago

0.4.0-develop-28

7 years ago

0.4.0-develop-27

7 years ago

0.4.0-develop-26

7 years ago

0.4.0-develop-24

7 years ago

0.4.0-develop-22

7 years ago

0.4.0-master-18

7 years ago

0.4.0

7 years ago

0.3.1-develop-21

7 years ago

0.3.1-master-17

7 years ago

0.3.1-master-16

7 years ago

0.3.1-master-15

7 years ago

0.3.1-develop-20

7 years ago

0.3.1

7 years ago

0.3.0-develop-19

7 years ago

0.3.0-master-14

7 years ago

0.3.0-develop-18

7 years ago

0.3.0-master-13

7 years ago

0.3.0-develop-17

7 years ago

0.3.0

7 years ago

0.2.0-develop-16

7 years ago

0.2.0-master-12

7 years ago

0.2.0-master-11

7 years ago

0.2.0-master-10

7 years ago

0.2.0-master-9

7 years ago

0.2.0-develop-14

7 years ago

0.2.0-master-8

7 years ago

0.2.0-develop-13

7 years ago

0.2.0

7 years ago

0.1.0-develop-12

7 years ago

0.1.0-develop-11

7 years ago

0.1.0-develop-10

7 years ago

0.1.0-develop-8

7 years ago

0.1.0-develop-7

7 years ago

0.1.0-develop-6

7 years ago

0.1.0-develop-5

7 years ago

0.1.0-master-7

7 years ago

0.1.0-develop-4

7 years ago

0.1.0-develop-3

7 years ago

0.1.0-master-6

7 years ago

0.1.0-develop-2

7 years ago

0.1.0

7 years ago

0.1.0-develop-1

7 years ago

0.1.0-master-5

7 years ago

0.1.0-master-4

7 years ago

0.1.0-master-2

7 years ago