All Projects → hypery2k → Nativescript Urlhandler

hypery2k / Nativescript Urlhandler

Licence: mit
NativeScript URL Handler Plugin

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Nativescript Urlhandler

Nativescript
NativeScript empowers you to access native platform APIs from JavaScript directly. Angular, Capacitor, Ionic, React, Svelte, Vue and you name it compatible.
Stars: ✭ 20,730 (+42206.12%)
Mutual labels:  nativescript
Nativescript Azure Mobile Apps
☁️ NativeScript plugin for working with Microsoft Azure Mobile Apps services
Stars: ✭ 31 (-36.73%)
Mutual labels:  nativescript
Nativescript Plugin Firebase
🔥 NativeScript plugin for Firebase
Stars: ✭ 990 (+1920.41%)
Mutual labels:  nativescript
Nativescript Particle
🕹 Control your https://particle.io devices from NativeScript
Stars: ✭ 19 (-61.22%)
Mutual labels:  nativescript
Shoutoutplay
The mobile app that allows you to create and record personal dedications using your favorite music playlists for corporate events, parties, weddings and get togethers.
Stars: ✭ 28 (-42.86%)
Mutual labels:  nativescript
Nativescript Cli
Command-line interface for building NativeScript apps
Stars: ✭ 977 (+1893.88%)
Mutual labels:  nativescript
Android Runtime
Android runtime for NativeScript (based on V8)
Stars: ✭ 399 (+714.29%)
Mutual labels:  nativescript
Nativescript Angular Drawer Template
A starter project to quickly create nativescript angular project with drawer pages.
Stars: ✭ 46 (-6.12%)
Mutual labels:  nativescript
Nativescript Flappy Bird
NativeScript implementation of Flappy Bird (basic). Demonstrates how to build games in NativeScript.
Stars: ✭ 31 (-36.73%)
Mutual labels:  nativescript
House
Proof of Concept and Research repository.
Stars: ✭ 37 (-24.49%)
Mutual labels:  nativescript
Nativescript Masked Text Field
#️⃣ A NativeScript Masked Text Field widget
Stars: ✭ 24 (-51.02%)
Mutual labels:  nativescript
Nativescript Headset Detection
Detect when a headphone (jack or bluetooth) is (dis)connected.
Stars: ✭ 11 (-77.55%)
Mutual labels:  nativescript
Nativescript Image Swipe
A NativeScript widget to easily 👆 and 🔍 through a list of images
Stars: ✭ 35 (-28.57%)
Mutual labels:  nativescript
Nativescript Vue
Native mobile applications using Vue and NativeScript.
Stars: ✭ 4,784 (+9663.27%)
Mutual labels:  nativescript
Https
Secure HTTP client with SSL pinning for Nativescript - iOS/Android
Stars: ✭ 45 (-8.16%)
Mutual labels:  nativescript
Docs
Documentation, API reference, and code snippets for NativeScript
Stars: ✭ 442 (+802.04%)
Mutual labels:  nativescript
Nativescript Keyframes
Facebook Keyframes plugin - if CSS animations don't cut it for ya
Stars: ✭ 32 (-34.69%)
Mutual labels:  nativescript
Flutter Egitim Serisi
Kesali Tech Youtube kanalında yayınlanan Flutter Eğitim serisi için kaynaklar ve video linkleri.
Stars: ✭ 48 (-2.04%)
Mutual labels:  nativescript
Nativescript Email
✉️ NativeScript plugin for opening draft e-mails
Stars: ✭ 45 (-8.16%)
Mutual labels:  nativescript
Ns Vue Radio
A native white-label application built with NativeScript-Vue for community radios
Stars: ✭ 36 (-26.53%)
Mutual labels:  nativescript

NativeScript URL Handler Plugin apple android

Greenkeeper badge Build Status Donate with Bitcoin

npm versionMaintainability

NPM

Feel free to donate

Or donate Bitcoins: bitcoin:3NKtxw1SRYgess5ev4Ri54GekoAgkR213D

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 [email protected]

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"
    ]

HTTPS intent

This lib also support HTTPS intent, you can define a host for it. Here is an example on Android with both custom & HTTPS scheme :

<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="my-app" />
</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="https" android:host="my-website.com" />
</intent-filter>

Let's suppose your put a <a href="https://my-website.com/check-our-app">Check our mobile app</a> link on your website to open your mobile app. Because https intent is also linked to the mobile browser, when user will tap on the link, a popup will appears to let the user choose between the browser and your mobile app to open this link.

In the other hand, if you setup a android:scheme="my-app" that only your app react to, putting a <a href="my-app://check-our-app">Check our mobile app</a> link like this on your website will avoid this popup and open your mobile app directly.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].