14

我可以在给定队列中发布通知并在另一个队列中接收吗?我想使用通知来传达不同的队列,但我不确定这是否安全......

4

2 回答 2

19

不可以。通知在发送它们的同一线程中传递,您需要以某种方式重新发送它才能将通知发送到您的线程。

于 2013-04-12T10:25:13.780 回答
14

No.

Apple's docs on the subject say: "Regular notification centers deliver notifications on the thread in which the notification was posted. [...] At times, you may require notifications to be delivered on a particular thread that is determined by you instead of the notification center. [...] In these cases, you must capture the notifications as they are delivered on the default thread and redirect them to the appropriate thread."

The following documentation from Apple might help: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html#//apple_ref/doc/uid/20001289-CEGJFDFG

于 2013-04-12T10:27:48.713 回答