我正在使用cordvoa开发一个安卓应用,并且使用cordova的$PushPlugin
实现了推送通知系统。
以下是我的PushPlugin代码 (源代码):
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);
});
当点击接收到的推送通知时,我希望将用户重定向到我的应用程序中的指定页面。我参考了这个(基于phonegap pushplugin),但是没有找到解决方案。任何帮助都将受到赞赏。
if(notification.foreground === false){ $location.path = ('/abc');}
,并且在module.run函数中也添加了$location
。但是当我点击通知时,重定向失败,我被重定向到了主页面。顺便说一下,我正在使用ngRouter。 - Lalitha Ramkumar