我创建了一个使用 NSTimer 的应用程序,它每秒触发一次。
我的问题是,如果 Iphone 处于睡眠模式,我会在事件触发前延迟 10 到 15 分钟。我已经stackoverflowed和google了这个,原因似乎是手机在睡眠模式下停止监听某些事件。
有些人通过播放静音而不让手机休眠来解决这个问题。
- 延迟的原因可能是什么?
- 静音解决方案似乎是一个非常“肮脏”的解决方案。有没有其他方法可以解决这个问题?
- 如果我使用静音解决方案,它会通过苹果审查吗?
代码:
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
}