1.When an event occurs, an object posts an appropriate notification to the notification center. (See “Posting a Notification” for more on posting notifications.) The notification center dispatches a message to each registered observer, passing the notification as the sole argument. It is possible for the posting object and the observing object to be the same.
Cocoa includes two types of notification centers:
a.The NSNotificationCenter class manages notifications within a single process.
b.The NSDistributedNotificationCenter class manages notifications across multiple processes on a single computer.
2.Each process has a default notification center that you access with the NSNotificationCenter +defaultCenter class method. This notification center handles notifications within a single process.A notification center delivers notifications to observers synchronously. In other words, when posting a notification, control does not return to the poster until all observers have received and processed the notification. To send notifications asynchronously use a notification queue, which is described in“Notification Queues.”
3.You register an object to receive a notification by invoking the notification center method addObserver:selector:name:object:, specifying the observer, the message the notification center should send to the observer, the name of the notification it wants to receive, and about which object. You don’t need to specify both the name and the object. If you specify only an object, the observer will receive all notifications containing that object. If you specify only a notification name, the observer will receive that notification every time it’s posted, regardless of the object associated with it.
浙公网安备 33010602011771号