Gar*_*ett 3 push-notification trigger.io
有没有办法知道什么时候通过推送通知打开应用程序?这对于将用户重定向到应用程序中针对该推送通知的相关位置将是有用的.
我使用此代码来查明我的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)
最初发布此答案的任何方式,以确定应用程序是直接打开还是由于通知
| 归档时间: |
|
| 查看次数: |
208 次 |
| 最近记录: |