睡眠模式与通知中心打开
在两者中, 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,当您锁定屏幕/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 whetherbgFlag
is set or not.Good luck.
有一些黑客可以检测锁定/解锁,但没有任何官方可以'未来的 iOS 版本不会中断。
There are some hacks to detect lock/unlock, but nothing official that couldn't break with a future iOS release.