有没有办法知道何时通过推送通知打开应用程序?这对于将用户重定向到应用程序中针对该推送通知的相关位置非常有用。
答案 0 :(得分:5)
我使用此代码查看我的Trigger.io应用程序是否通过Parse推送通知打开:
var appLastResumed = new Date();
window.forge.event.appResumed.addListener(function() {
window.appLastResumed = new Date();
// additional code that runs when the app is resumed
});
window.forge.event.messagePushed.addListener(function() {
// this event fires every time a user clicks on a push notification
// no matter whether the app is already opened or not
// so we need to detect whether this happened right after an appResumed event
setTimeout( function() { // make sure the appResumed event is fired first
if (new Date().getTime() - window.appLastResumed.getTime() < 1000) {
// app was opened by a push notification
// insert your code here
}
}, 50);
});
最初在Any way to figure out if the app is opened directly or because of a notification
上发布了此答案