O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required