Posts Tagged ‘UIApplicationWillEnterForegroundNotification’
Cordova has lifecycle events – “pause” and “resume” which are documented in http://docs.phonegap.com but there are two more events for iOS that are undocumented, “resign” and “active”. These events correspond to when the app is leaving the active state (UIApplicationWillResignActiveNotification) and when the app enters the active state (UIApplicationDidBecomeActiveNotification), respectively.
In iOS 4, the “resign” and “active” events can be used to detect when the Wake/Lock button has been pressed exclusively, but in iOS 5, this has slightly changed. In iOS 5, the “pause” (UIApplicationDidEnterBackgroundNotification) and “resume” (UIApplicationWillEnterForegroundNotification) events are triggered as well (see the section Moving to the Background) BUT only if your app’s UIApplicationExitsOnSuspend setting in your Info.plist is NO (i.e. multi-tasking is enabled) .
This in essence tells devs that apps when in the “locked” state are put into the background as well if the app is allowed to multi-task in iOS 5, while in iOS 4, locking will never put your app into the background, ever.
iOS devices that do not support multitasking (the iPhone 3G and iPod Touch 2nd Generation – even under iOS 4), and apps that set their UIApplicationExitsOnSuspend setting in their app’s Info.plist to YES (i.e. no multi-tasking), will never get the “pause” and “resume” events, of course.
tldr; So – if you want to have your app still in the foreground running when your device is locked – and you are running iOS 5 – you will have to DISABLE multi-tasking for your app (UIApplicationExitsOnSuspend set to YES).