我正在使用cordova开发Android应用,并使用cordova $PushPlugin
实现推送通知系统。
我的PushPlugin代码(source):
module.run(function($rootScope,$cordovaPush) {
var androidConfig = {
"senderID": "replace_with_sender_id",
};
document.addEventListener("deviceready", function(){
$cordovaPush.register(androidConfig).then(function(result) {
// Success
}, function(err) {
// Error
})
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
alert('registration ID = ' + notification.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
});
// WARNING: dangerous to unregister (results in loss of tokenID)
$cordovaPush.unregister(options).then(function(result) {
// Success!
}, function(err) {
// Error
})
}, false);
});
点击收到的推送通知后,我想将用户重定向到我的应用中的指定页面。我提到this(基于phonegap pushplugin)但无法找到解决方案。任何帮助将不胜感激。
答案 0 :(得分:1)
如果您检查对象notification
的结构,您会看到有一个属性foreground
,当您从点击通知进入应用时,该属性将为false。您可以使用它来放置逻辑
case 'message':
if(notification.foreground === false){
//add logic for navigation to your specific page i.e $state.go('myPage')
}