Use the NSNotificationCenter addObserverForName:object:queue:usingBlock: OR the addObserver:selector:name:object: method and pass nil for the name and object.
Example
The following code should complete the task:
- (void)dumpNotifications { NSNotificationCenter *notifyCenter = [NSNotificationCenter defaultCenter]; [notifyCenter addObserverForName:nil object:nil queue:nil usingBlock:^(NSNotification *notification){
Documents
Here are the docs on addObserverForName:object:queue:usingBlock: In particular, see Name Parameters and obj.
addObserverForName: Object: Queues: usingBlock:
Adds an entry to the recipient sending table with the notification queue and a block for adding to the queue, as well as additional criteria: notification name and sender.
- (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block
Options
name
The name of the notification for which the observer is being registered; that is, only notifications with this name are used to add a block to the operation queue. If you pass zero, the notification center does not use the notification name to decide whether to add a block to the operation queue.
Obj
The object whose notifications you want to add to the operation queue block. If you pass zero, the notification center does not use the notification sender to decide whether to add a block to the operation queue.
queues
The operational queue to which the block should be added. If you pass zero, the block runs synchronously in the posting flow.
block
The block that will be executed when a notification is received. The block is copied by the notification center and (copy) stored until the observer registration is deleted. The block takes one argument:
notification
Notification.
Sam Oct 31 2018-11-11T00: 00Z
source share