Ionic3 怎么打开第三方 app,最简单粗暴的方法

一、安装可检测 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) => { /* 未安装,请编写提示代码或跳转下载 */ } );

}

} 

  

posted on 2018-09-25 09:35  jurui  阅读(1536)  评论(0编辑  收藏  举报