Creating Notification Queues

- initWithNotificationCenter:

Initializes and returns a notification queue for the specified notification center.

Example

NSNotificationQueue *notificationQueue = [[NSNotificationQueue alloc]initWithNotificationCenter:[NSNotificationCenter defaultCenter]];
NSLog(@"%@",notificationQueue);
		

Output

2014-04-16 04:42:54.081 iOS-Tutorial[475:a0b] 
		

Getting the Default Queue

+ defaultQueue

Returns the default notification queue for the current thread.

Example

NSNotificationQueue *notificationQueue = [NSNotificationQueue defaultQueue];
NSLog(@"%@",notificationQueue);
		

Output

2014-04-16 04:44:20.478 iOS-Tutorial[508:a0b] 
		

Managing Notifications

- enqueueNotification: postingStyle:

Adds a notification to the notification queue with a specified posting style.

Example

NSNotification *notification = [[NSNotification alloc] initWithName:@"Eezy" object:@"my object" userInfo:@{@"Status": @"Success"}];
NSNotificationQueue *notificationQueue = [NSNotificationQueue defaultQueue];
NSLog(@"%@",notificationQueue);
[notificationQueue enqueueNotification:notification postingStyle:NSPostASAP];
		

- enqueueNotification: postingStyle: coalesceMask: forModes:

Adds a notification to the notification queue with a specified posting style, criteria for coalescing, and runloop mode.

Example

NSNotification *notification = [[NSNotification alloc] initWithName:@"Eezy" object:@"my object" userInfo:@{@"Status": @"Success"}];
NSNotificationQueue *notificationQueue = [NSNotificationQueue defaultQueue];
NSLog(@"%@",notificationQueue);
[notificationQueue enqueueNotification:notification postingStyle:NSPostASAP coalesceMask:NSNotificationNoCoalescing forModes:@[NSRunLoopCommonModes]];		
	

- dequeueNotificationsMatching: coalesceMask:

Removes all notifications from the queue that match a provided notification using provided matching criteria.

Example

NSNotification *notification = [[NSNotification alloc] initWithName:@"Eezy" object:@"my object" userInfo:@{@"Status": @"Success"}];
NSNotificationQueue *notificationQueue = [NSNotificationQueue defaultQueue];
[notificationQueue enqueueNotification:notification postingStyle:NSPostWhenIdle];
NSLog(@"%@",notificationQueue);
[notificationQueue dequeueNotificationsMatching:notification coalesceMask:NSNotificationNoCoalescing];
		

Advertisements