iPhone 开发:Notification

注:本文是一份学习笔记。

 

Notifications:

In every application, there is an instance of NSNotificationCenter, which works like a smart bulletin board. An object can register as an observer (“Send any ‘lost dog’ notifications to me.”). When another object posts a notification (“I lost my dog.”), the notification center forwards that notification to the appropriate registered observers.

 

This is important: the notification center does not retain the observers. If you have an object that registered itself with the notification center, that object should unregister itself before it is deallocated. If an object does not unregister itself from the notification center, the next time any notification it was registered for is posted, the center will try and send the object a message. But that object will have been deallocated, and your application will crash.

 

UIDevice Notifications:

One object that regularly posts notifications is UIDevice. Here are the constants for the notifications that a UIDevice posts:

UIDeviceOrientationDidChangeNotification

UIDeviceBatteryStateDidChangeNotification

UIDeviceBatteryLevelDidChangeNotification

UIDeviceProximityStateDidChangeNotification

你可能感兴趣的:(notification)