如何使用包含令牌的深层链接打开 Android 应用程序?

问题描述

我正在从一个离子应用程序生成一个 android 应用程序,我想在我点击包含使用深层链接的令牌 (http://localhost:8100/signup/token) 的注册链接时打开它。我该怎么做以及如何传递令牌参数?

解决方法

基本上你想要这个插件:https://github.com/ionic-team/ionic-plugin-deeplinks

这一切都在 Github 页面中进行了解释,但让我们看看:

1 - 安装插件:

cordova plugin add ionic-plugin-deeplinks
--variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com
--variable ANDROID_PATH_PREFIX=/

使用 DEEPLINK_SCHEME + URL_SCHEME 参数,您可以设置域来检测链接并将用户带到您的应用。在上面的例子中:

https://myapp

但这是一项本机功能,您只能在设备上进行测试,而不能使用 ionic serve。

2 - 然后在你的 app.component.ts 中:

this.platform.ready().then(() => {
      this.deeplinks.route({
        '/about-us': HomePage,'/products/:productId': HelpPage
      }).subscribe(match => {
        // match.$route - the route we matched,which is the matched entry from the arguments to route()
        // match.$args - the args passed in the link
        // match.$link - the full link data
        console.log('Successfully matched route',match);
      },nomatch => {
        // nomatch.$link - the full link data
        console.error('Got a deeplink that didn\'t match',nomatch);
      });
});

要获取您的参数,请使用“signup/:token”之类的路由,您可以在 match.$args 中获取该参数(“argument”),如上所示。