3
是否有任何方式知道应用程序何时通过推送通知打开?这对于将用户重定向到该推送通知的应用内的相关位置很有用。Trigger.IO:知道什么时候通过推送通知打开应用程序
是否有任何方式知道应用程序何时通过推送通知打开?这对于将用户重定向到该推送通知的应用内的相关位置很有用。Trigger.IO:知道什么时候通过推送通知打开应用程序
我用这个代码来看看我的Trigger.io应用程序是通过解析推送通知开:
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