【问题标题】:Push notifications using parse in javascript在 javascript 中使用 parse 推送通知
【发布时间】:2015-07-21 22:26:28
【问题描述】:

我正在使用解析来发送推送通知,而我的移动应用程序基于 Ionic(angularjs)。我目前正在通过渠道发送推送通知。如果我想在用户点击通知时打开特定页面,我该怎么做?我当前的代码是

window.parsePlugin.initialize('waDzmmDVt7hNmRCoY50wOFN3lsRoW2xu42WrPYLs', 'IF2RHNA0slYDq8feUhweewmcK2uEnOqDnK8J7jUf', function() {
  console.log('Parse initialized successfully.');

  window.parsePlugin.subscribe('SampleChannel', function() {
    console.log('Successfully subscribed to SampleChannel.');

      window.parsePlugin.getInstallationId(function(id) {
        // update the view to show that we have the install ID
        console.log('Retrieved install id: ' + id);               

      }, function(e) {
        console.log('Failure to retrieve install id.');
      });

  }, function(e) {
      console.log('Failed trying to subscribe to SampleChannel.');
  });

}, function(e) {
    console.log('Failure to initialize Parse.');
});

【问题讨论】:

    标签: javascript android angularjs parse-platform ionic-framework


    【解决方案1】:

    你需要注册一个回调

    https://github.com/aaronksaunders/dcww/blob/master/www/js/parseService.js#L60

    registerCallback: function (_pushCallback) {
        var deferred = $q.defer();
        $window.parsePlugin.registerCallback('onNotification', function () {
    
            $window.onNotification = function (pnObj) {
    
                _pushCallback && _pushCallback(pnObj);
    
                alert('We received this push notification: ' + JSON.stringify(pnObj));
                if (pnObj.receivedInForeground === false) {
                    // TODO: route the user to the uri in pnObj
                }
            };
            deferred.resolve(true);
    
        }, function (error) {
            deferred.reject(error);
        });
        return deferred.promise;
    
    }
    

    在此处查看完整示例:https://github.com/aaronksaunders/dcww

    【讨论】:

      【解决方案2】:

      使用自定义接收器作为here

      然后将context.startActivity(intent) 的标志用作here

      您也可以询问intent.getAction() 以了解哪个意图过滤器启动您的接收器

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        相关资源
        最近更新 更多