当iphone处于睡眠模式时,Iphone应用程序会延迟10-15分钟 [英] Iphone app is delayed for 10 -15 minutes when iphone is in sleep mode

查看:286
本文介绍了当iphone处于睡眠模式时,Iphone应用程序会延迟10-15分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用NSTimer的应用程序,它每秒都会被触发。

I have created an app that uses NSTimer, which gets triggered each second.

我的问题是,如果Iphone处于睡眠模式,我会延迟10在事件触发前至15
分钟。我有堆栈溢出并用Google搜索这个
,原因似乎是手机在睡眠模式下停止侦听某些
事件。

My problem is that if the Iphone is in sleep mode i get a delay for 10 to 15 minutes before the event is triggered. I have stackoverflowed and googled this and the reason for this seems to be that the phone stops listening for certain events when in sleep mode.

有些人通过播放静音来解决这个问题,不允许
手机睡觉。

Some people have solved this issue by playing a mute sound, not allowing the phone to sleep.


  1. 延迟的原因是什么?

  2. 静音解决方案似乎是一个非常脏的。还有其他方法可以解决这个问题吗?

  3. 如果我使用静音解决方案,它会通过苹果评论吗?

代码:

timer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(goAction)userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

-(void)goAction {
  // Here i check for some dates and then call the activateBeepAlarmView 
}


推荐答案

因为没有人回答我的三个问题所以我必须回答这些问题:

Well since no one has answered my three questions I will have to answer them:

1。可能是延迟的原因是什么?
我将不得不引用 Ben S


在您的应用程序上调用applicationWillResignActive后,您只需停止接收事件:
当应用程序从活动状态转换为非活动状态时,委托可以实现此方法以进行调整。当应用程序处于非活动状态时,它正在执行但不会调度传入事件。当弹出覆盖窗口或设备被锁定时会发生这种情况。

Once applicationWillResignActive gets called on your application you simply stop receiving events: The delegate can implement this method to make adjustments when the application transitions from an active state to an inactive state. When an application is inactive, it is executing but is not dispatching incoming events. This occurs when an overlay window pops up or when the device is locked.

睡眠模式是节省能源。为此,设备会停止侦听您要求的事件。 NSTimer事件仍将触发,因为它们不需要昂贵的(电池式)硬件监控。此外,使用NSTimer实现警报,因此即使在睡眠状态下它们也需要能够运行。否则,人们可能不会醒来并责备他们的iPhone。

The point of sleep mode is to save energy. To do so, the device stops listening for events like the ones you're asking for. NSTimer events will still fire since they don't require expensive (battery-wise) hardware monitoring. Also, alarms are implemented using NSTimer, so they need to be able to function even when in sleep. Otherwise, people might not wake up and blame their iPhone.

2。静音解决方案似乎是一个非常脏的解决方案。还有其他方法可以解决这个问题吗?

不,目前我还没有找到另一个解决方案,如果我错了,请随时纠正我。
查看这个博客文章如何操作。

2. The mute sound solution seems to be a very "dirty" one. Is there some other way to solve this?
No, currently I haven't found another solution, please feel free to correct me if I'm wrong. Check out this blog post how to do it.

3。如果我使用静音解决方案,它会通过苹果审查吗?

这篇关于当iphone处于睡眠模式时,Iphone应用程序会延迟10-15分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆