Push notification Trigger.IO:通过推送通知知道何时打开应用程序

Push notification Trigger.IO:通过推送通知知道何时打开应用程序,push-notification,trigger.io,Push Notification,Trigger.io,有没有办法通过推送通知知道应用程序何时打开?这将有助于将用户重定向到该推送通知的应用程序内的相关位置。我使用此代码查找我的Trigger.io应用程序是否由解析推送通知打开: var appLastResumed = new Date(); window.forge.event.appResumed.addListener(function() { window.appLastResumed = new Date(); // additional code that runs when

有没有办法通过推送通知知道应用程序何时打开?这将有助于将用户重定向到该推送通知的应用程序内的相关位置。

我使用此代码查找我的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);
});
var applastersumed=new Date();
window.forge.event.appResumed.addListener(函数(){
window.applastersumed=新日期();
//应用程序恢复时运行的其他代码
});
window.forge.event.messagePushed.addListener(函数(){
//每次用户单击推送通知时,都会触发此事件
//无论应用程序是否已打开
//因此,我们需要检测这是否发生在所评估的事件之后
setTimeout(函数(){//确保首先触发appResumed事件
if(new Date().getTime()-window.applastersumed.getTime()<1000){
//应用程序已通过推送通知打开
//在这里插入您的代码
}
}, 50);
});
最初在早些时候发布了这个答案