我正在尝试建立一个带有解析的推送通知,以处理收到的通知。
我使用了phonegap-parse-plugin插件,并能够正确设置它。
我的问题是我无法处理收到的通知。我想基于通知json参数将用户重定向到通知页面。
因此,我决定切换到parse-push-plugin,但是我的问题是我什至无法获取它来显示警报注册框。它甚至找不到ParsePushPlugin方法。
我遵循了非常简单的教程,并将其添加到我的app.js文件中
ParsePushPlugin.register(
{ appId:"xxx", clientKey:"xxx", eventKey:"myEventKey" }, //will trigger receivePN[pnObj.myEventKey]
function() {
alert('successfully registered device!');
},
function(e) {
alert('error registering device: ' + e);
});
ParsePushPlugin.on('receivePN', function(pn){
alert('yo i got this push notification:' + JSON.stringify(pn));
});
警报成功只是未能显示,所以我想它没有用,或者我没有做正确的事。
最佳答案
使用phonegap-plugin-push。它易于实现和使用。
配置:
var push = PushNotification.init({
"android": {
"senderID": "Your-sender-ID",
"forceShow": true, // To show notifications on screen as well
"iconColor": "#403782",
"badge": "true",
"clearBadge": "true" // To clear app badge
},
"ios": {
"alert": "true",
"badge": "true",
"clearBadge": "true",
"sound": "true",
"forceShow": "true"
},
"windows": {}
});
设备注册:
push.on('registration', function(data) {
localStorage.setItem('pushToken', data.registrationId); // Save registration ID
});
处理通知
push.on('notification', function(data) {
console.log(data);
// Handle all requests here
if (data.additionalData.$state == "mystate") {
$state.go('app.conversations');
}
})
关于angularjs - 用ionic解析推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29771478/