【问题标题】:Handling a parse push notification with cordova push plugin使用 cordova 推送插件处理解析推送通知
【发布时间】:2015-04-23 01:10:03
【问题描述】:

我正在尝试构建一个可用于获取推送通知数据并在 angularJS 范围内处理它的应用程序。推送即将到达设备,我将它们显示在托盘上。当我单击推送时 - 应用程序打开。但我无法在 JS 中接收数据。 这些插件已安装:https://github.com/phonegap-build/PushPluginhttps://github.com/avivais/phonegap-parse-plugin

parsePlugin.initialize('xxxxxxxxxxxxxxx', 'xxxxxxxxxxxxx', function() {
    //okay, we are registered!
    parsePlugin.getInstallationObjectId(function(data) {
        alert('Okay!');
    }, function(e) {
        alert('error');
    });
}, function(e) {
    alert('error while authenticating!');
});

嗯,它正在注册。我还有一个 onNotification 函数,由 PushPlugin 调用

var onNotification = function(e) // This never happens :(
{
            alert("Push came!");
            angular.element(document.getElementById('pushCtrl')).scope().getMessage(e);
            angular.element(document.getElementById('pushCtrl')).scope().$apply();
};

然后什么也没有发生。典型的应用行为是“好的!”并在推送后仅发送到设备。

另外,如果我插入 PushPlugin 注册功能,应用程序在尝试解析 regid 时崩溃:

   $cordovaPush.register({"senderID": "xxxxxxxxxx","ecb": "onNotificationGCM"}).then(function(token) {
        if(token="OK"){
            $scope.net=true; //show a net icon in the top of the screen
        }
    }, function(err) {
        $scope.token = err;
    });
}

这有什么问题?我可以将数据推送到应用程序吗?

【问题讨论】:

    标签: javascript android cordova parse-platform


    【解决方案1】:

    我不知道您的代码是否有效,但我注意到一个错误。 对于 $cordovaPush.register,您的“ecb”值为“onNotificationGCM”;但之前你声明了“onNotification”(var onNotification = function(e)..........)

    将“ecb”值更改为“onNotification”。

    希望对你有帮助!!!!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 2017-12-02
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多