是否可以知道 iPhone 何时进入睡眠状态?
是否有任何通知可以提醒我手机将进入睡眠状态?我已经实现了以下内容:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(resignActive:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
但当手机在一段时间不活动后(在我的设置中为 1 分钟)进入睡眠状态时,它似乎不会被触发。我认为它不起作用的原因是我有一个计时器,每秒执行一个操作,如果经过了一定时间(大于一分钟),它会发出音频警报。在我的 resignActive 中,我使计时器无效,当我按下主页按钮时,计时器工作正常,但当手机进入睡眠状态时,计时器就不起作用。它似乎仍在后台运行,但“速度较低”,因为时间比正常情况长得多(大约 10 分钟而不是 2 分钟)。
你知道手机进入睡眠状态时会发生什么吗?我读过这两篇文章,但它并没有真正回答我的问题。
Is there any notification I can listen to that will alert me that the phone will go to sleep? I have implemented the following:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(resignActive:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
but it seems that it's not getting triggered when the phone goes to sleep after some time of inactivity (1 min in my settings). The reason I think it's not working is that I have a timer that perform an action every second and if a certain time has passed (bigger than one minute) it issues an audio alarm. In my resignActive I invalidate my timer and that works fine when I press the home button, but not when the phone goes to sleep. It still seems to be running in the background but "at a lower speed" as the times are much longer than normal (around 10 min instead of 2 min).
Any ideas what's happening when the phone goes to sleep? I have read these two posts but it doesn't really answer my question.
What happens to an iPhone app when iPhone goes into stand-by mode?
Iphone app is delayed for 10 -15 minutes when iphone is in sleep mode
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 UIApplicationDelegate 上实现这 2 个方法:
当显示来自另一个应用程序(或 SMS)的推送通知时也会调用它......
Implements those 2 methods on the UIApplicationDelegate :
It will be called also when a push notification from another app (or a SMS) is shown...