[英]App in background w/ setTimeout and push notification
We're running into an issue where Push Notification code is being executed before the setTimeout handler is executed when the app is coming into the foreground.我们遇到了一个问题,即当应用程序进入前台时,在执行 setTimeout 处理程序之前执行推送通知代码。 Here is the sequence of events:以下是事件的顺序:
setTimeout(this.logout, 10000)
gets called. setTimeout(this.logout, 10000)
被调用。this.logout
callback will not be invoked until the app is bought back into the foreground.因为应用在后台, this.logout
直到应用被买回前台才会调用this.logout
回调。this.logout
code is executed immediately. this.logout
代码立即执行。The result is that the user is kicked out of the app before he can view the Push Notification.结果是用户在查看推送通知之前就被踢出了应用程序。
Is there a way to somehow re-arrange the events in the Event Queue so that this.logout is executed first and Push Notification handling code executed second?有没有办法以某种方式重新排列事件队列中的事件,以便先执行 this.logout,然后执行推送通知处理代码?
Edit: We're using the Expo Push Notifications SDK编辑:我们正在使用 Expo Push Notifications SDK
Sample Code示例代码
componentDidMount() {
this.notifications = Notifications.addListener(this.handleNotification);
this.timeout = setTimeout(this.logout, 10000);
}
componentWillUnmount() {
Notifications.remove(this.notifications);
}
this.handleNotification = () => { ... }
this.logout = () => { ... }
我通过关闭 setTimeout 计时器并使用时间戳 (Date.now() - startTime) 来查找经过的时间来解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.