[英]How to open specific page in the app on clicking Push Notification?
我正在使用cordova开发Android应用程序,并使用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),但无法找到解决方案。 任何帮助将不胜感激。
这是一个简单的解决方案,不使用任何角度路线。
case 'message':
if (notification.foreground === false){
window.location = '#/abc';
window.location.reload();
}
如果检查对象notification
结构,您将看到有一个属性foreground
,当您从单击通知进入应用程序时,该属性将为false。 你可以用它来表达你的逻辑
case 'message':
if(notification.foreground === false){
//add logic for navigation to your specific page i.e $state.go('myPage')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.