我需要在applicationDidEnterBackground
中执行某些操作。但我需要区分哪些用户操作导致“输入背景”:屏幕锁定或主页按钮按下。在iOS7上区分屏幕锁定和主屏幕按钮
我使用这个代码,这是从这个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");
}
它工作正常,在iOS6的。但在iOS7(包括设备和模拟器)上,我总是得到UIApplicationStateBackground
,无论用户是单击home还是锁定按钮。
有人有什么可能导致这种情况的想法吗? iOS 7更新到多任务后台处理?或者我的应用程序的某些设置(我的应用程序的背景模式关闭)?
是否有替代解决方案?
可能的重复[如何区分screen loc k和主页按钮在iOS5上按?](http://stackoverflow.com/questions/8303703/how-to-differentiate-between-screen-lock-and-home-button-press-on-ios5) – jmort253
我想我没有说清楚。我在链接上阅读了这篇文章,但这在iOS7中不再适用。我不认为这是重复的。但无论如何,我编辑我的问题来说清楚。 – Perisheroy
好主意澄清,再加上编辑颠倒你的帖子回到顶部,让其他人再次看到它。 :D – jmort253