diff --git a/ionic/plugins/applinks/applinks.ts b/ionic/plugins/applinks/applinks.ts new file mode 100644 index 0000000000..5a47458e11 --- /dev/null +++ b/ionic/plugins/applinks/applinks.ts @@ -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'); + } + }); + } +} diff --git a/ionic/plugins/plugins.ts b/ionic/plugins/plugins.ts index ed313ea108..4d4de5b501 100644 --- a/ionic/plugins/plugins.ts +++ b/ionic/plugins/plugins.ts @@ -1,4 +1,5 @@ export * from './plugin' +export * from './applinks/applinks' export * from './barcode/barcode' export * from './battery/battery' export * from './camera/camera'