2013-08-21 51 views

回答

5

我用这个代码来看看我的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