gpt4 book ai didi

ios - UNUserNotificationCenter 线程安全

转载 作者:行者123 更新时间:2023-12-05 07:41:05 27 4
gpt4 key购买 nike

按照文档的要求,如果它们在同一个线程上,则一个接一个地删除和添加具有匹配标识符的通知对我来说似乎工作正常。如果它们在不同的线程上,则新添加的通知将被上一行的 delete 调用删除。第一个案例保证有效吗?

根据文档,removePendingNotificationRequests“异步执行,在辅助线程上删除挂起的通知请求。”我了解什么是异步与同步,但在我看来,UNUserNotificationCenter 一直处于阻塞状态,直到删除完成。是吗?

我想在这种情况下我不能完全确定术语线程安全。只要一次在一个线程上使用中心对象,是否对辅助线程上的那些异步调用进行管理?或者这是否意味着如果它在多个线程中使用它可能会崩溃?

UNUserNotificationCenter

Thread-Safety Information

You may use the shared user notification center object from any thread of your app. However, you should use this object from only one thread at a time. Do not try to use it from multiple threads simultaneously. Always assign your delegate object to the shared user notification center's delegate property before using the object. It is a programmer error to assign a delegate after calling methods that might return information to that delegate.

最佳答案

Apple's documentation现在说共享的 UNUserNotificationCenter 对象可以安全地从多个线程使用,即使是在同一时间:

You may use the shared user notification center object simultaneously from any of your app’s threads. The object processes requests serially in the order that the system initiates them.

关于ios - UNUserNotificationCenter 线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45599395/

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