1.判断是Android还是ios
if (this.platform.is('ios')) {
this.scheme =自己定义的';
} else if (this.platform.is('android')) {
this.scheme ='包名';
}
2.装插件appAvailability 用于检测是否装上app
ionic cordova plugin add cordova-plugin-appavailability
npm install --save @ionic-native/app-availability
this.appAvailability.check(this.scheme).then(value=>{
debugger
alert(value);
//打开app
this.openApp();
},Error=>{
alert("插件失败")
}
openApp(){
var sApp = (<any>window).startApp.set({
// "action":"ACTION_MAIN",
// "category":"CATEGORY_DEFAULT",
// "type":"text/css",
"package":"包名",
"uri":"file://data/index.html",
"flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"],
// "component": ["com.android.GoBallistic","com.android.GoBallistic.Activity"],
"intentstart":"startActivity",
}, { /* extras */
"EXTRA_STREAM":"extraValue1",
"extraKey2":"extraValue2"
});
sApp.start(function(){
alert('返回成功');
},function(Error){
alert("返回失败");
})
}
3.如果是ios的时候
要打开的app中info.polist中
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>自己定义的</string>
<array>
<key>CFBundleURLName</key>
<string>包名</string>
</dict>
</array>
在当前app中info.polist中
<key>LSApplicationQueriesSchemes</key>
<array>
<string>自己定义的</string>
</array>
使用时
window.location.href=this.scheme
ionic3先检测是否安装了app,没有就安装,有则打开
最新推荐文章于 2021-06-23 22:35:00 发布