feat(app-launcher): add plugin

related: #2889
This commit is contained in:
Daniel Sogl 2019-02-14 16:37:41 +01:00
parent 41c6bcafe6
commit 9bdb2fac9d

View File

@ -0,0 +1,66 @@
import { Injectable } from '@angular/core';
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';
export interface AppLauncherOptions {
uri?: string;
packageName?: string;
}
/**
* @name App Launcher
* @description
* Simple Cordova plugin to see if other apps are installed and launch them.
*
* @usage
* ```typescript
* import { AppLauncher, AppLauncherOptions } from '@ionic-native/app-launcher/ngx';
* import { Platform } from '@ionic/angular';
*
* constructor(private appLauncher: AppLauncher, private platform: Platform) { }
*
* ...
*
* const options: AppLauncherOptions = {
* }
*
* if(this.platform.is('ios')) {
* options.uri = 'fb://'
* } else {
* options.packageName = 'com.facebook.katana'
* }
*
* this.appLauncher.canLaunch(options)
* .then((canLaunch: boolean) => console.log('Facebook is available'))
* .catch((error: any) => console.error('Facebook is not available'));
*
* ```
*/
@Plugin({
pluginName: 'AppLauncher',
plugin: 'cordova-plugin-app-launcher',
pluginRef: 'window.plugins.launcher',
repo: 'https://github.com/nchutchind/cordova-plugin-app-launcher',
platforms: ['Android', 'iOS']
})
@Injectable()
export class AppLauncher extends IonicNativePlugin {
/**
* Check if any apps are installed that can launch via a specified URI or Package Name.
* @param options App Launcher options
* @return {Promise<any>} Returns a promise that resolves if the app is installed
*/
@Cordova()
canLaunch(options: AppLauncherOptions): Promise<boolean> {
return;
}
/**
* Launches the app via a specified URI or Package Name
* @param options App Launcher options
* @return {Promise<any>} Returns a promise that resolves the launched app
*/
@Cordova()
launch(options: AppLauncherOptions): Promise<any> {
return;
}
}