首页 > 解决方案 > 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')
                    }
                });

标签: angularionic-frameworkdeep-linking

解决方案


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 按照这个链接你得到你所有的答案。


推荐阅读