睡眠模式与通知中心打开

发布于 2024-12-29 17:44:38 字数 189 浏览 2 评论 0原文

在两者中, 1) iPhone 进入睡眠模式 2)打开通知中心

它调用

- (void)applicationWillResignActive:(UIApplication *)application

有什么方法可以识别这个方法是因为设备进入睡眠模式还是因为打开通知中心而被调用?

in both,
1) iPhone goes in Sleep mode
2) Open notification Center

It calls

- (void)applicationWillResignActive:(UIApplication *)application

Is there any way to identify if this method is called because device went in to sleep mode or by opening notification center?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

桃酥萝莉 2025-01-05 17:44:38

好的,当您锁定屏幕/iPhone 进入睡眠模式时,最前面的应用程序(您的应用程序)将进入后台模式,并且当您下拉通知中心时,你的应用程序实际上没有被推送到后台。

因此,您可以使用

- (void)applicationWillEnterForeground:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

来设置一个值,例如 bgFlag,在您的应用程序委托类中,

然后,当调用 - (void)applicationDidBecomeActive:(UIApplication *)application 时,您检查是否bgFlag 是否设置。

祝你好运。

OK, When you lock your screen/iPhone goes to sleep mode, the front most app(Your app) will go to background mode, and when you pull down the Notification Center, you app actually is not pushed to background.

So, you can use

- (void)applicationWillEnterForeground:(UIApplication *)application

or

- (void)applicationDidEnterBackground:(UIApplication *)application

to set a value, say bgFlag, in your app delegate class,

then, when - (void)applicationDidBecomeActive:(UIApplication *)application is invoked, you check whether bgFlag is set or not.

Good luck.

掐死时间 2025-01-05 17:44:38

有一些黑客可以检测锁定/解锁,但没有任何官方可以'未来的 iOS 版本不会中断。

There are some hacks to detect lock/unlock, but nothing official that couldn't break with a future iOS release.

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