Question

If notification fired by child thread, then post it by NSNotificationQueue (of course invoked in child thread) but working handler in main thread, the handler won't be called. But if the notification fired in main thread, it works as expected.

Does Apple mean the notification sender and handler must be in the same thread? If Yes, NSNotificationQueue seems not be so helpful. Anyone who knows it please share and thanks in advance.

[[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP coalesceMask:(NSNotificationCoalescingOnName) forModes:nil];
Was it helpful?

Solution

They will be in the same thread. If you need multithreading look atNSOperationQueue

Edited:

From NSNotificationQueue class reference: Every thread has a default notification queue, which is associated with the default notification center for the task. You can create your own notification queues and have multiple queues per center and thread.

And:

+ (id)defaultQueue Returns the default notification queue for the current thread. This notification queue uses the default notification center.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top