任何方式来确定应用程序是直接打开还是由于通知

has*_*ipe 2 trigger.io

无法弄清楚如何获得启动选项(如果它甚至可能).想要了解如何找出应用程序启动机制 - 也就是说应用程序是由用户直接启动还是由于通知.使用新的Safari智能应用横幅时甚至会有所帮助.

有类似问题的人吗?任何解决方法或解决方案?

干杯!

Pat*_*lph 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);
});
Run Code Online (Sandbox Code Playgroud)