17.6. Handling Local System Notifications

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:

NSCurrentLocaleDidChangeNotification

This notification is delivered to applications when the user changes her locale; for instance, if the user switches her iOS device’s language from English to Spanish in the Settings page of the device.

NSUserDefaultsDidChangeNotification

This notification is fired when the user changes the application’s settings in the Settings page of the iOS device (if any settings are provided to the user).

UIDeviceBatteryStateDidChangeNotification

This 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 batteryState property of an instance of UIDevice.

UIDeviceProximityStateDidChangeNotification

This notification gets sent whenever the state of the proximity sensor changes. The last state is available through the proximityState property of an instance of UIDevice.

Discussion

When your application is in the ...

Get iOS 7 Programming Cookbook 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.