Ionic3 怎麼開啟第三方 app,最簡單粗暴的方法
阿新 • • 發佈:2019-02-11
一、安裝可檢測 APP 是否安裝的外掛
ionic cordova plugin add cordova-plugin-appavailability
npm install --save @ionic-native/app-availability
二、安裝可呼叫原生瀏覽器的外掛
ionic cordova plugin add cordova-plugin-inappbrowser
npm install --save @ionic-native/in-app-browser
三、引入到 app.module.ts
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { AppAvailability } from '@ionic-native/app-availability';
···
providers: [
InAppBrowser,AppAvailability
]
四、以 Home.ts 為例
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser' ;
import { AppAvailability } from '@ionic-native/app-availability';
import { Platform } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-Home',
templateUrl: 'Home.html',
})
export class Home {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private iab : InAppBrowser,
private appAvailability: AppAvailability,
private platform: Platform
) { }
ionViewDidLoad() {
var app = '';
if (this.platform.is('ios')) {
app = 'weixin://'; /* 微信的Scheme URL */
} else if (this.platform.is('android')) {
app = 'com.tencent.mm'; /* 微信的安卓包名 */
}
this.appAvailability.check(app) /* 檢測微信是否已安卓 */
.then(
(yes: boolean) => {
this.iab.create('weixin://', '_system'); /* 開啟微信 */
},
(no: boolean) => {
/* 未安裝,請編寫提示程式碼或跳轉下載 */
}
);
}
}