I need to do something in applicationDidEnterBackground
. But I need to differentiate which user action causes the "enter background": screen lock or home button press.
I was using this code, which is from this post - How to differentiate between screen lock and home button press on iOS5?:
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
NSLog(@"Sent to background by locking screen");
} else if (state == UIApplicationStateBackground) {
NSLog(@"Sent to background by home button/switching to other app");
}
It works fine on iOS6. but on iOS7 (both device and simulator), I always get UIApplicationStateBackground
, whether the user clicks the home or the lock button.
Does someone have an idea about what could cause this? iOS 7 updates to multi-task background handling? Or some setting of my app (my app's background mode is off)?
And is there an alternative solution?