angular - Ionic 应用深层链接无法正常工作
问题描述
在此代码中,当我单击按钮时,它总是打开https://apps.apple.com URL 而不是打开 App Store。我想实现,如果应用程序没有安装在设备中,那么它应该只去 App Store,否则它应该打开这个 URL:https://apps.apple.com。
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) => {
this.appLauncher.launch(options);
})
.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')
}
});
解决方案
App.addListener('appUrlOpen', (data: any) => {
console.log(data,"chintan");
this.zone.run(() => {
// Example url: https://beerswift.app/tabs/tab2
// slug = /tabs/tab2
const slug = data.url.split("apps.").pop();
if (slug == "apple.com") {
// DO SOMTHING
}
else {
this.router.navigateByUrl("/");
}
// If no match, do nothing - let regular routing
// logic take over
});
});
在您的intializeApp ()方法中将此代码添加到appcomponent.ts中,如果您为 android 运行,还可以在清单文件中添加一些行。
https://capacitorjs.com/docs/guides/deep-links 按照这个链接你得到你所有的答案。
推荐阅读
- python - 如何每次迭代更新单个嵌套字典
- javascript - 将图像(base64)附加到输入类型=“文件”
- android - 如何在 android studio 中设置当前 Xcode 版本?
- python - 带有 pygame 状态的平滑运动
- c++ - C++虚拟指针及其机制
- amazon-web-services - 带有 S3 存储桶的 AWS Cloudfront 配置为从裸域重定向到 www
- java - 如何避免 WorkManager Periodic Fetch Task 与我的主要 App Fetch 方法并行运行?
- python-3.x - 如何从 s3 下载图像并将其存储为变量而不是将其存储在目录中?
- angular - 订阅 Angular 响应式表单提交
- node.js - Nodejs等待不等待