Ionic应用deep links功能异常 点击跳转App Store而非唤起应用如何解决?
问题根因
你遇到的问题由两个原因导致:
- iOS 9及以上系统对自定义URI Scheme的查询做了权限限制,没有在Info.plist的
LSApplicationQueriesSchemes字段中声明的Scheme,调用canLaunch会直接返回false/抛出错误,直接走到catch分支跳转应用商店 - 现有代码逻辑没有对
canLaunch返回的布尔值做判断,部分场景下canLaunch不会抛出错误,只会返回无法唤起的布尔值,你没有对该状态做对应跳转商店的处理
修复步骤
1. 配置iOS URI Scheme查询白名单
在你项目的ios/App/App/Info.plist文件中添加如下配置,声明你要查询的exiapp Scheme:
<key>LSApplicationQueriesSchemes</key> <array> <string>exiapp</string> </array>
2. 修正业务代码逻辑
补全canLaunch返回结果的判断逻辑,同时保留异常分支的兜底跳转:
popover.onDidDismiss() .then(async (decision) => { if (exiStatus.status === 'registered' && decision.data) { const options: AppLauncherOptions = {} if (this.platform.is('ios')) { options.uri = 'exiapp://referral' } else { options.packageName = 'com.iprescribeexercise.app.android.iPrescribe' } this.appLauncher.canLaunch(options) .then((canLaunch: boolean) => { if (canLaunch) { // 设备已安装应用直接唤起 this.appLauncher.launch(options); } else { // 设备未安装应用跳转商店 if (this.platform.is('ios')) { window.open('https://apps.apple.com') } else { window.open('https://play.google.com/store/apps/details?id=com.iprescribeexercise.app.android.iPrescribe') } } }) .catch((error: any) => { // 接口调用异常兜底跳转商店 if (this.platform.is('ios')) { window.open('https://apps.apple.com') } else { window.open('https://play.google.com/store/apps/details?id=com.iprescribeexercise.app.android.iPrescribe') } }); } })
可选优化
如果你的应用适配了iOS通用链接(Universal Link),可以直接用通用链接替代自定义Scheme,不需要配置查询白名单,唤起成功率更高,也不会弹出系统确认弹窗。
内容的提问来源于stack exchange,提问作者naresh mandloi
相关产品推荐
相关产品推荐

