我正在尝试构建一个可用于获取推送通知数据并在 angularJS 范围内处理它的应用程序。推送即将进入设备,我将它们显示在托盘上。当我单击推送时 - 应用程序打开。但是我无法接收 JS 中的数据。这些插件已安装:https://github.com/phonegap-build/PushPlugin 和 https://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();
};
什么也没发生。典型的应用行为是"好的!",推送发送后,它只会到达设备。
另外,如果我插入推送插件注册功能,应用程序在尝试解析注册时崩溃:
$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;
});
}
这是怎么回事?我可以将数据推送到应用程序吗?
我不知道你的代码是否可以工作,但我注意到一个错误。对于$cordovaPush.register,您的"ecb"值为"onNotificationGCM";但早些时候你声明了"onNotification"(var onNotification = function(e(..........(
将"ECB"值更改为"onNotification"。
我希望它有所帮助!!!!