Search code examples
objective-ciosnsnotificationcenter

UIApplicationWillEnterForegroundNotification is not called when app is briefly closed


The UIApplicationDidBecomeActiveNotification and UIApplicationDidBecomeActiveNotification notifications do not seem to be called when the app is only briefly closed.

Specifically: when the app enters the foreground it should check to see if any settings in the settings app were changed. If you go right to the settings app, change something, and come right back, the notifications are sometimes not sent. After closing and reopening the app again, they are called and everything is ok.

Is there a better way to consistently detect when the app enters the foreground? or could something be causing a conflict and keeping these notifications from being sent?


Solution

  • Rather than trying to catch every foreground transition, just watch for changes in the settings, no matter how they happen, by watching NSUserDefaultsDidChangeNotification. See How to get an update NSUserDefault on iOS 4?