iPhone - 区分 UIApplicationDidBecomeActiveNotification 通知
注册 UIApplicationDidEnterBackgroundNotification 时,我注意到当设备进入睡眠模式时不会触发此通知。
但是,当唤醒它时,会触发 UIApplicationDidBecomeActiveNotification 通知。从后台模式返回时也会触发它。
那么我如何知道我的应用程序是否从后台模式返回,或者在设备唤醒后被激活?
When registering the UIApplicationDidEnterBackgroundNotification, I notice that this notification is not triggered when the device enters in sleep mode.
But, when waking it up, the UIApplicationDidBecomeActiveNotification notification is triggered. It is also triggered when coming back from background mode.
So how can I know if my application comes back from background mode, or is activated following a wake up of the device ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些并不相互平衡;它们是为不相关的事件而发布的。我相信您在检测到应用程序从后台返回时需要
UIApplicationWillEnterForegroundNotification
,在检测某些其他情况(包括睡眠)时需要UIApplicationWillResignActiveNotification
。请注意UIApplicationWillResignActiveNotification
> 还显示诸如“来电被忽略”和“操作系统显示不属于您的进程的警报”(例如短信)等事件。Those don't balance each other; they are posted for unrelated events. I believe you want
UIApplicationWillEnterForegroundNotification
when detecting your app coming back from the background, andUIApplicationWillResignActiveNotification
when detecting certain other situations (including sleep.)Note that
UIApplicationWillResignActiveNotification
also shows for events such as "incoming phone call was ignored" and "the operating system displayed an alert that is not part of your process" (e.g. a text message.)