【问题标题】:Integrating Branch.io in Ionic App在 Ionic App 中集成 Branch.io
【发布时间】:2016-04-19 04:50:24
【问题描述】:

我正在尝试从我的网站发送我的应用程序的链接,链接中带有一个令牌,如下所示:

branch.link({
  stage: 'new user',
  data: {
       token: 543322
   }},
   function(err, link) {
    console.log(err, link);
});

然后当用户单击链接后安装应用程序时,我想获取此令牌来注册用户。 我尝试阅读 Branch.io 文档并实施它,但它不起作用。 有人可以告诉我一个如何使它工作的例子吗? 我的应用控制器中的代码是这样的

(():void => {
  'use strict';
  angular
    .module('xyz')
    .controller('abc', abc);

    function abc (
      $window
    ) {
      let vm = this;

      $window.Branch.setDebug(true);
      $window.Branch.initSession().then(function (res) {
        console.log(res);
        alert('Response: ' + JSON.stringify(res));
       }).catch(function (err) {
         console.error(err);
         alert('Error: ' + JSON.stringify(err));
      });

      $window.Branch.getFirstReferringParams().then(function (res) {
        // Success Callback
        alert('res'+res);
      }).catch(function (err) {
        // Error Callback
        alert('err'+err);
      });

      $window.Branch.getLatestReferringParams().then(function (res) {
        // Success Callback
        alert(res);
      }).catch(function (err) {
        // Error Callback
        alert(err);
      });

      function DeepLinkHandler (data) {
       alert('Data from initSession: ' + data.data);
      }

      $window.DeepLinkHandler = DeepLinkHandler;

})();

【问题讨论】:

    标签: ionic-framework deep-linking branch.io


    【解决方案1】:

    来自 Branch here 的 Alex:此过程分为三个步骤:

    1。创建链接

    您已经使用您在问题中提供的代码执行此操作。

    2。将 Branch SDK 集成到您的应用中

    包含此步骤的文档页面在这里:https://dev.branch.io/getting-started/sdk-integration-guide/guide/cordova/

    3。注意传入的链接,并路由它

    涵盖您需要的文档页面在这里:https://dev.branch.io/getting-started/deep-link-routing/advanced/cordova/

    基本上,它是一个看起来像这样的函数:

    function DeepLinkHandler(data) {
        console.log("received data: " + JSON.stringify(data));
        for (key in data) {
            if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
                console.log(key + ": " + data["key"]);
            }
        }
    
        if (data["token"]) {
            // load the view to register the user based on your token
        } else {
            // load your normal view
        }
    }
    

    【讨论】:

    • 我已经在做这一切了。但是在 initSession 之后没有调用 DeepLinkHandler。我已将代码添加到问题中。告诉我我做错了什么。
    猜你喜欢
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多