简体   繁体   English

使用cordova推送插件处理解析推送通知

[英]Handling a parse push notification with cordova push plugin

I'm trying to build an app that will be available to get Push notification data and process it in angularJS scope. 我正在尝试构建一个可用于获取Push通知数据并在angularJS范围内对其进行处理的应用。 Pushes are coming to device and I have them displayed on tray. 推送即将到设备,我将它们显示在托盘上。 When I click push - app opens. 当我单击“推”时-应用将打开。 But I can't recieve a data in JS. 但是我无法在JS中接收数据。 These plugins are installed: https://github.com/phonegap-build/PushPlugin and https://github.com/avivais/phonegap-parse-plugin 这些插件已安装: 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!');
});

Well, it's registering. 好吧,它正在注册。 Also I have an onNotification function there, called by PushPlugin 我那里也有一个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();
};

And nothing happens. 没有任何反应。 Typical app behavior is 'Okay!' 典型的应用行为是“好!” and after push sending it gets to the device only. 并在推送发送后将其仅发送到设备。

Also, if I insert PushPlugin registration function, app crashes while trying to resolve regid: 另外,如果我插入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;
    });
}

What's wrong with this? 这怎么了 Am I able to get push data to app? 我可以获取推送数据到应用程序吗?

I don't know if your code is will work but i noticed one error. 我不知道您的代码是否可以正常工作,但我注意到一个错误。 for $cordovaPush.register, your "ecb" value is "onNotificationGCM"; 对于$ cordovaPush.register,您的“ ecb”值为“ onNotificationGCM”; but earlier you declared "onNotification" (var onNotification = function(e)..........) 但是您之前声明了“ onNotification”(var onNotification = function(e)..........)

change "ecb" value to "onNotification". 将“ ecb”值更改为“ onNotification”。

i hope it helps!!!!! 我希望它可以帮助!!!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM