npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-plugin-universal-links

v2.0.0

Published

Universal links (IOS) and App Links (Android) support for NativeScript.

Downloads

97

Readme

Nativescript plugin Universal Links

Universal links (IOS) and App Links (Android) support for NativeScript apps.

When a user clicks a link to a website, it opens in the default web browser (Safari/Chrome). Universal linking allows your app to open instead of the web browser.

Apple calls this Universal Links and Google calls it App Links, but they mean the same thing.

Install this plugin using: npm install nativescript-plugin-universal-links

Implementing Universal Links

Both iOS (9.0 and newer) and Android (all versions) provide good APIs for universal linking.

IOS

Apple introduced a new deep linking API in iOS 9.0 called “Universal Links”. It provides a better user experience than the hacky deep linking options that existed in iOS 8.0 and below.

First step is to add a file to the root of your website called apple-app-site-association. This is a JSON file and it looks like this:

{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "your-team-id.com.example",
                "paths": [ "/blog/*"]
            }
        ]
    }
}
  • this file will be downloaded automatically by every single user that installs or upgrades your iOS app.
  • it MUST be served over HTTPS with a valid SSL certificate. If you need to test this, I recommend using https://ngrok.io
  • because this file is only fetched once when the user first installs or upgrades the app, this file must be live on your website before your app is released. This also means that you can’t add new deep linking url patterns to your app until you push out a new app update to force users to refresh the file.

Check out Apples' docs for more info.

Next, you need to add the Associated Domains to your IOS project, either using XCode or manually adding the following code to your App_Resources/IOS/app.entitlements file. Please note the applinks: prefix, it won't work without it.

<key>com.apple.developer.associated-domains</key>
<array>
  <string>applinks:www.example.com</string>
</array>

Android

In Android, universal linking is implemented using Intent Filters. By adding a BROWSABLE intent filter, you are saying that your app can be started by a user clicking on a website url.

You don't need any server side changes for Android, only modify your app to add the Intent Filter. Add this code to your App_Resources/Android/src/main/AndroidManifest.xml file:

<activity
    android:name="com.tns.NativeScriptActivity"
    android:label="@string/title_activity_kimera" >

    <!-- Add this new section to your Activity -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- Handle urls starting with "https://www.example.com/blog" -->
        <data android:scheme="https"
              android:host="www.example.com"
              android:pathPrefix="/blog" />
    </intent-filter>
</activity>

Using the plugin

Call the registerUniversalLinkCallback in your AppComponent's ngOnInit method to provide a callback method which will receive an Universal Link object every time your app is opened by a website link:

import { Component, OnInit } from "@angular/core";
import { registerUniversalLinkCallback } from "nativescript-plugin-universal-links";

@Component({
  selector: "my-app",
  template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent {
  constructor() {}

  ngOnInit() {
    registerUniversalLinkCallback(ul => {
      // use the router to navigate to the screen
    });
  }
}

The universal link object has the following structure:

{
  "href": "https://www.example.com/blog?title=welcome",
  "origin": "https://www.example.com",
  "pathname": "/blog",
  "query": "?title=welcome"
}

There is also a getUniversalLink() method that will return the last universal link which opened the app. This is useful in scenarios where your app is protected by a login screen. Check if the user is authenticated and then navigate to the desired path.

import { getUniversalLink } from "nativescript-plugin-universal-links";

const ul = getUniversalLink();