【发布时间】:2013-11-04 22:20:41
【问题描述】:
我需要在applicationDidEnterBackground 做点什么。但我需要区分导致“进入背景”的用户操作:屏幕锁定或主页按钮按下。
我使用的是这段代码,来自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。
有人知道可能导致这种情况的原因吗? iOS 7 更新多任务后台处理?或者我的应用程序的某些设置(我的应用程序的后台模式已关闭)?
还有其他解决方案吗?
【问题讨论】:
-
我觉得我说得不够清楚。我阅读了您链接上的帖子,但这在 iOS7 中不再起作用。我不认为它是重复的。但无论如何,我编辑我的问题以使其清楚。
-
澄清的好主意,加上编辑会将您的帖子推回到顶部,以便其他人再次看到它。 :D
-
@Perisheroy 我也有同样的问题。你找到解决这个问题的方法了吗?如果找到请帮助我。
标签: ios objective-c cocoa-touch ios7 uiapplication