AppLinks info

This commit is contained in:
Max Lynch
2015-09-15 15:15:00 -05:00
parent e741608f05
commit 6bcf1e112d
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,71 @@
import * as Rx from 'rx';
import * as util from 'ionic/util';
import {NativePlugin} from '../plugin';
/**
* Open installed apps on the device. Note: Android and iOS have different ways of
* opening and specifying launch params, so they have separate launch functions.
*
* Example:
*
* if(platform.is('ios') {
* AppLinks.check('twitter://').then((installed) => {
* AppLinks.openIOS('twitter://user?screen_name=ionicframework')
* }, (err) => {
*
* })
* } else if(platform.is('android') {
* AppLinks.check('com.twitter.android').then((installed) => {
* AppLinks.openAndroid([["action", "VIEW"], ['twitter://user?screen_name=ionicframework']])
* })
* }
*/
@NativePlugin({
name: 'AppLinks',
platforms: ['ios', 'android'],
engines: {
cordova: 'cordova-plugin-statusbar'
},
pluginCheck: () => {
return !!navigator.startApp;
}
})
export class AppLinks {
/**
* Open app on iOS with a given URL (iOS), or scheme (Android)
*/
static openIOS(url) {
this.ifPlugin(() => {
navigator.startApp.start(url)
})
}
/**
* Open app on Android with a given scheme and params.
*/
static openAndroid(args) {
this.ifPlugin(() => {
navigator.startApp.start(...args);
})
}
/**
* Check if an installed app can be opened from the given URL.
*/
static canOpen(urlOrScheme) {
return new Promise((resolve, reject) => {
let hasPlugin = this.ifPlugin(() => {
navigator.startApp.check(urlOrScheme, (message) => {
resolve(message);
}, function(err) {
reject(err);
});
});
if(!hasPlugin) {
reject('Plugin not installed');
}
});
}
}

View File

@ -1,4 +1,5 @@
export * from './plugin' export * from './plugin'
export * from './applinks/applinks'
export * from './barcode/barcode' export * from './barcode/barcode'
export * from './battery/battery' export * from './battery/battery'
export * from './camera/camera' export * from './camera/camera'