2

我有一个关于通知服务扩展生命周期的问题,我已经搜索过,但我找不到适合我的问题的答案。问题是当旧通知正在处理(尚未称为 contentComplete)时出现新通知时会发生什么?

根据我的测试,它将结束旧进程并使用更新的通知开始新的处理,用户将错过旧通知,所有数据尚未保存。真的吗?

4

1 回答 1

2

我不是绝对肯定,但根据此处找到的 Signal 通知服务扩展代码,您所说的是正确的。他们解决它的方式是这样的:

// 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. 

确保你看到他们的其余代码

于 2020-07-01T09:57:59.087 回答