12.8. Handling Notifications Delivered to a Waking App
Problem
When your application is brought to the foreground, you want to be able to get notifications about important system changes such as the user’s locale changes.
Solution
Simply listen to one of the many system notifications that iOS sends to waking applications. Some of these notifications are listed here:
NSCurrentLocaleDidChangeNotificationThis notification is delivered to applications when the user changes her locale: for instance, if the user switches his iOS device’s language from English to Spanish in the Settings page of the device.
NSUserDefaultsDidChangeNotificationThis notification is fired when the user changes the application’s settings in the Settings page of the iOS device (if any setting is provided to the user).
UIDeviceBatteryStateDidChangeNotificationThis notification gets sent whenever the state of the battery of the iOS device is changed. For instance, if the device is plugged into a computer when the application is in the foreground and then unplugged when in the background, the application will receive this notification (if the application has registered for this notification). The state can then be read using the
batteryStateproperty of an instance ofUIDevice.UIDeviceProximityStateDidChangeNotificationThis notification gets sent whenever the state of the proximity sensor changes. The last state is available through the
proximityStateproperty of an instance ofUIDevice.
Discussion
When your application ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access