3

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

4

1 回答 1

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);
});

最初在以任何方式确定应用程序是直接打开还是因为通知而发布的早期答案

于 2013-08-21T11:39:15.843 回答