【问题标题】:How to open an android app using a deeplink that contains a token?如何使用包含令牌的深层链接打开 Android 应用程序?
【发布时间】:2021-02-26 10:03:52
【问题描述】:

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

【问题讨论】:

    标签: android ionic-framework deep-linking ionic-native


    【解决方案1】:

    基本上你想要这个插件: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”),如上所示。

    【讨论】:

    • 问题是当我写 http 或 https 作为 url_scheme 它不起作用
    • 当我写 localhost:8100 作为主机时它也不起作用(localhost:8100
    • 首先,http或https不是url_scheme,那是deeplink_scheme:DEEPLINK_SCHEME://URL_SCHEME。所以 localhost 将是 url_scheme,而 https 是深度链接方案。
    • 其次,显然它不适用于本地主机。我建议你的是一个原生插件,你需要在你的设备中使用如下方案对其进行测试:https://myapp
    猜你喜欢
    • 1970-01-01
    • 2019-05-19
    • 2016-06-26
    • 2021-12-20
    • 2021-01-26
    • 2016-05-10
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    相关资源
    最近更新 更多