Giter VIP home page Giter VIP logo

nativescript-open-app's Introduction

NativeScript Open App plugin

A NativeScript plugin for opening other applications on the device (with app store fallback)

Installation

Run the following command from the root of your project:

tns plugin add nativescript-open-app

Usage

Android

To open an app, you need its id (for example "com.facebook.katana" for Facebook and "com.twitter.android" for Twitter). You can easily find it in app's URL on https://play.google.com.

Examples

Open Facebook app if it is installed on the device (open Facebook app's entry in Play Store otherwise):

var openApp = require("nativescript-open-app").openApp;

var installed = openApp("com.facebook.katana");
console.log("Is it installed? " + installed);

Open Facebook app if it is installed on the device (do nothing otherwise):

var openApp = require("nativescript-open-app").openApp;

var installed = openApp("com.facebook.katana", false);
console.log("Is it installed? " + installed);

Open Facebook app if it is installed on the device (open facebook.com otherwise):

var openApp = require("nativescript-open-app").openApp;
var utils = require("utils/utils");

var installed = openApp("com.facebook.katana", false);
if (!installed) {
    utils.openUrl("https://facebook.com");
}

Simple TypeScript example:

import { openApp } from "nativescript-open-app";

openApp("com.facebook.katana");

iOS

To open an app on iOS you need a schema registered by the app. Additionally you are required to whitelist the schemas for all apps you want to be able to open. Add them to your app/App_Resources/iOS/Info.plist (and additionally include "itms-apps" schema used by the App Store):

  <key>LSApplicationQueriesSchemes</key>
  <array>
    <string>itms-apps</string>
    <string>twitter</string>
  </array>

Examples

Open Facebook app if it is installed on the device (do nothing otherwise):

var openApp = require("nativescript-open-app").openApp;

var installed = openApp("fb://");
console.log("Is it installed? " + installed);

Open Facebook app if it is installed on the device (open Facebook app's entry in App Store otherwise). The third argument to openApp is the app's id in App Store (you can easily find it in app's URL on https://itunes.apple.com):

var openApp = require("nativescript-open-app").openApp;

var installed = openApp("fb://", true, "284882215");
console.log("Is it installed? " + installed);

Open Facebook app if it is installed on the device (open facebook.com otherwise):

var openApp = require("nativescript-open-app").openApp;
var utils = require("utils/utils");

var installed = openApp("fb://", false);
if (!installed) {
    utils.openUrl("https://facebook.com");
}

Simple TypeScript example:

import { openApp } from "nativescript-open-app";

openApp("fb://");

nativescript-open-app's People

Contributors

ludwiktrammer avatar vtrifonov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.