考虑一下这个场景。我有一个ionic / angular应用程序,我正在使用ngcordova插件来推送通知。现在让我们假设当应用程序在后台时,一个推送通知到达。用户,查看应用程序抽屉中的通知,然后单击通知以了解更多信息。我希望用户使用$location.path()导航到特定的路径。如何进入通知点击事件?
发布于 2015-05-16 07:09:26
好的。事实证明,不需要点击通知单击事件。您可以使用以下命令检查应用程序是否在前台:
notification.foreground
所以,如果
if(notification.foreground) {
//do something for the case where user is using the app.
$popup('A notification just arrived');
} else {
//do something for the case where user is not using the app.
$location.path('/tab/somepage');
}
发布于 2016-04-22 05:37:59
如果你使用的是phonegap-plugin-push,这可以很简单的完成。
push.on('notification', function(data) {
if(data.additionalData.foreground){
//Do stuff you want to do if app is running on foreground while push notification received
}else{
//Do stuff you want to do if the app is running on background while the push notification received
}
});
https://stackoverflow.com/questions/30260665
复制