gpt4 book ai didi

ios - 通知服务扩展生命周期

转载 作者:行者123 更新时间:2023-12-04 09:36:21 25 4
gpt4 key购买 nike

我有一个关于通知服务扩展生命周期的问题,我进行了搜索,但找不到适合我的问题的答案。问题是在处理旧通知(尚未称为 contentComplete)时出现新通知时会发生什么?
根据我的测试,它将结束旧进程并使用新通知开始新处理,用户将错过旧通知,所有数据尚未保存。真的吗?

最佳答案

我不是绝对肯定,但基于 Signal 的通知服务扩展代码发现 here ,你说的对。他们解决的方法是这样的:

// The lifecycle of the NSE looks something like the following:
// 1) App receives notification
// 2) System creates an instance of the extension class
// and calls this method in the background
// 3) Extension processes messages / displays whatever
// notifications it needs to
// 4) Extension notifies its work is complete by calling
// the contentHandler
// 5) If the extension takes too long to perform its work
// (more than 30s), it will be notified and immediately
// terminated
//
// Note that the NSE does *not* always spawn a new process to
// handle a new notification and will also try and process notifications
// in parallel. `didReceive` could be called twice for the same process,
// but will always be called on different threads. To deal with this we
// ensure that we only do setup *once* per process and we dispatch to
// the main queue to make sure the calls to the message fetcher job
// run serially.
确保你看到他们的其余代码

关于ios - 通知服务扩展生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62566948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com