我需要做点什么applicationDidEnterBackground.但我需要区分哪个用户操作导致"输入背景":屏幕锁定或按下主页按钮.
我正在使用这个代码,这是从这篇文章 - 如何区分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");
}
Run Code Online (Sandbox Code Playgroud)
它在iOS6上运行良好.但是在iOS7(设备和模拟器)上UIApplicationStateBackground,无论用户是单击主页还是锁定按钮,我总能得到.
有人知道可能导致这种情况的原因吗?iOS 7更新到多任务后台处理?或者我的应用程序的某些设置(我的应用程序的后台模式已关闭)?
还有替代解决方案吗?