【发布时间】:2011-12-06 22:43:45
【问题描述】:
我有一个应用需要在使用 Home 按钮发送到后台时执行某些操作,而在使用顶部硬件按钮锁定设备时执行其他操作。解决这些需求的标准方法是UIApplication 发出的通知和委托方法。在 iOS 4 上,它们如下所示:
// Pressing the home button
Will resign active.
Did enter background.
// Tapping app icon on Springboard
Will enter foreground.
Did become active.
// Pressing the lock button
Will resign active.
// Unlocking the device
Did become active.
换句话说,很容易区分锁定和后台。在 iOS 5 上,行为发生了变化:
// Pressing the home button
Will resign active.
Did enter background.
// Tapping app icon on Springboard
Will enter foreground.
Did become active.
// Pressing the lock button
Will resign active.
Did enter background.
// Unlocking the device
Will enter foreground.
Did become active.
注意didEnterBackground 和willEnterForeground 通知现在即使在(取消)锁定设备时也会发出,因此无法区分锁定和后台。此更改是否记录在某处?是回归吗?你知道区分这两种情况的另一种方法吗?
【问题讨论】:
-
Apple 显然不希望您区分这些事件。因此,如果您确实找到了解决方法,它可能会导致您的应用被拒绝。
-
它在文档中找不到问题,而且它在 iOS 4 中的工作方式有所不同,所以对我来说似乎并不“清楚”。
-
我就是这样做的。 stackoverflow.com/questions/19595928/… 两者都适用于 iOS6 和 iOS7。
标签: ios cocoa-touch