iPhone - 区分 UIApplicationDidBecomeActiveNotification 通知

发布于 2024-12-05 12:44:06 字数 202 浏览 1 评论 0原文

注册 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-12-12 12:44:08

这些并不相互平衡;它们是为不相关的事件而发布的。我相信您在检测到应用程序从后台返回时需要 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, and UIApplicationWillResignActiveNotification 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文