Saturday, December 26, 2015

What is notification in iOS?

The notification mechanism of Cocoa implements one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects - the observed object - creates a notification object and posts it to a notification centre. The notification centre determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, which contains the notification name, the observed object, and a dictionary containing any supplemental information.Posting a notification is a synchronous procedure. The posting object doesn’t regain control until the notification centre has broadcast the notification to all observers. For asynchronous behaviour, you can put the notification in a notification queue; control returns immediately to the posting object and the notification centre broadcasts the notification when it reaches the top of the queue.Regular notifications - that is, those broadcast by the notification centre - are intraprocess only. If you want to broadcast notifications to other processes, you can use the distributed notification centre and its related API.