asemolotion
1/29/2018 - 7:37 AM

ionic-native

v2 and v3 inappbrowser, appavailability, device

https://stackoverflow.com/questions/43149291/what-is-the-difference-between-ionic-native-and-ionic-native-xxx-in-ionic-2

The difference is between ionic-native v 2.x and ionic native v3.x

ionic-native v 2.x
If this is the version, all cordova wrappers will be available in the particular package and the plugins are used as global objects imported directly from ionic-native.
V2 readme.

ionic native v3.x
This is the current version (as of now 3.4.4). You need to install npm install @ionic-native/core and then install the individual package.@ionic-native/[package-name]
For use you need to inject the plugin as a provider. Check answer here
参考 https://forum.ionicframework.com/t/ionic-opening-external-app/77932/3

興味深いけど、inappbrowserをaddしたらfacebook pluginが動かなくなるので
保留。(0129)

ionic plugin add cordova-plugin-inappbrowser
ionic plugin add cordova-plugin-appavailability
ionic plugin add cordova-plugin-device

import { InAppBrowser, AppAvailability, Device } from 'ionic-native';

launchExternalApp(iosSchemaName: string, androidPackageName: string, appUrl: string, httpUrl: string, username: string) {
	let app: string;
	if (Device.device.platform === 'iOS') {
		app = iosSchemaName;
	} else if (Device.device.platform === 'Android') {
		app = androidPackageName;
	} else {
		let browser = new InAppBrowser(httpUrl + username, '_system');
		return;
	}

	AppAvailability.check(app).then(
		() => { // success callback
			let browser = new InAppBrowser(appUrl + username, '_system');
		},
		() => { // error callback
			let browser = new InAppBrowser(httpUrl + username, '_system');
		}
	);
}

openInstagram(username: string) {
	this.launchExternalApp('instagram://', 'com.instagram.android', 'instagram://user?username=', 'https://www.instagram.com/', username);
}

openTwitter(username: string) {
	this.launchExternalApp('twitter://', 'com.twitter.android', 'twitter://user?screen_name=', 'https://twitter.com/', username);
}

openFacebook(username: string) {
	this.launchExternalApp('fb://', 'com.facebook.katana', 'fb://profile/', 'https://www.facebook.com/', username);
}