Chapter 6. Notification Processing
WHAT'S IN THIS CHAPTER?
Working with notifications
How to register to receive notifications
The NSNotificationCenter object
How to implement a local notification
iOS 4, like any other GUI environment, reflects an infinite series of events. Touches, swipes, connecting to a network, and the keyboard appearing are just a few examples of events. Notifications are broadcast when these events occur. An application registers to receive these notifications, in order to act when the event occurs.
The actual notification is encapsulated in an NSNotification
object that will be broadcast. The NSNotification
is then broadcast to the NSNotificationCenter
. The application that wants to receive the notifications must register with the NSNotificationCenter
in order to receive the notifications by adding themselves as an observer:.
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
To find out what notifications are sent by a particular class, look in the documentation for the class; the notification will be listed in the Notifications section. For example, the UIWindow
class reference lists:
UIWindowDidBecomeVisibleNotification
UIWindowDidBecomeHiddenNotification
UIWindowDidBecomeKeyNotification
UIWindowDidResignKeyNotification
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
Use ...
Get Professional iPhone® and iPad™ Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.