Wednesday, January 28, 2015

"Notification" in Objective C ?

provides a mechanism for broadcasting information within a program, using notification we can send message to other object by adding observer.
When the event does happen, a notification is posted to the notification center(NSNotificationCenter), which immediately broadcasts the notification to all registered objects. Optionally, a notification is queued in a notification queue, which posts notifications to a notification center after it delays specified notifications.
An NSNotification object ( notification) contains a name, an object, and an optional dictionary. The name is a tag identifying the notification. The object is any object that the poster of the notification wants to send to observers of that notification—typically the object that posted the notification itself. The dictionary may contain additional information about the event.
Other objects can register themselves with the notification center as observers to receive notifications when they are posted. The notification center takes care of broadcasting notifications to the registered observers.
Ex:- 1. registering [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rbtUserSubscriptionStatusChanged:) name:SUBSCRIPTION_STATUS_CHANGED_NOTIFICATION object:nil];
2. sending/posting notification [[NSNotificationCenter defaultCenter] postNotificationName:SUBSCRIPTION_STATUS_CHANGED_NOTIFICATION object:self userInfo:nil];
  • The NSNotificationCenter class manages notifications within a single process.
  • The NSDistributedNotificationCenter class manages notifications across multiple processes on a single computer.Posting a distributed notification is an expensive operation.  The notification gets sent to a systemwide server that then distributes it to all the processes that have objects registered for distributed notifications.

NSNotificationQueue objects, or simply, notification queues, act as buffers for notification centers.

0 comments:

Post a Comment

About

Blog Archive

Powered by Blogger.

Blog Archive