简体   繁体   English

自iPhone3以来,idleTimerDisabled无法正常工作

[英]idleTimerDisabled not working since iPhone 3.0

I have used: 我用过:

[UIApplication sharedApplication].idleTimerDisabled = YES;

in a number of Apps developed and running under iPhone OS 2.x and never had any problems with it. 在iPhone OS 2.x下开发和运行的许多应用程序中都没有任何问题。 They were clock apps so needed to run constantly and ignore the iPhone's idle Timer setting. 它们是时钟应用程序,因此需要不断运行并忽略iPhone的闲置计时器设置。

However, trying to achieve the same with a new App running OS 3.0 (and which needs to be deployed under 3.0 as it uses some 3.0 APIs) I've found the idle Timer to be either ignored or inconsistent. 但是,尝试使用运行OS 3.0的新应用程序(并且需要在3.0下部署,因为它使用一些3.0 API)时,我发现空闲的Timer要么被忽略要么不一致。

My App plays music from the iPod library and when the music is playing it auto-locks regardless of the above setting. 我的应用程序播放iPod库中的音乐,当音乐播放时,无论上述设置如何,它都会自动锁定。 But once you unlock it, it then doesn't auto-lock again unless you play music again, in which case it locks again after the iPhone auto-lock time setting. 但是一旦你解锁它,它就不会再次自动锁定,除非你再次播放音乐,在这种情况下它会在iPhone自动锁定时间设置后再次锁定。

I'm amazed no-one else has come across this as I imagine it would affect a large number of Apps. 我很惊讶没有其他人遇到这个,因为我想它会影响大量的应用程序。

Just to clarify: 只是为了澄清:
1. The above code is in ApplicationDidFinishLaunching 1.上面的代码在ApplicationDidFinishLaunching中
2. I know that the phone won't auto-lock when testing from xCode regardless of settings 2.我知道无论设置如何,从xCode测试时手机都不会自动锁定

If anyone has any thoughts I'd be very grateful... 如果有人有任何想法,我会非常感激......

Our app uses the MPMediaPLayer . 我们的应用程序使用MPMediaPLayer We also had the idleTimerDisabled=YES code in the ApplicationFinishedLaunching , which works EXCEPT if untethered, and there is already a current nowPlayingItem which is left playing (or unpaused, if paused at app startup). 我们在ApplicationFinishedLaunching也有idleTimerDisabled=YES代码,如果不受限制,它的工作时间为EXCEPT,并且已经存在当前正在播放的nowPlayingItem (如果在应用启动时暂停,则取消暂停)。 Obviously this is all with the Settings -> General -> Autolock set to some timed value. 显然,只需将Settings -> General -> Autolock设置为某个定时值即可。

By adding idleTimerDisabled=NO , immedately followed by idleTimerDisabled=YES in one of the other bits of code AFTER we had figured out what bit of music we would get playing seemed to solve the problem. 通过添加idleTimerDisabled=NO ,在其他一些代码之后立即跟随idleTimerDisabled=YES我们已经知道我们将要播放的音乐似乎可以解决问题。 Just setting it to YES was insufficient.. and subsequent queries had always indicated the correct value ( YES ).. so it appears the Apple code ignores the setting of the value IF there is a current piece of music and that is not changed by your code.. but does notice a change of value. 只是将其设置为YES是不够的..后续查询总是指示正确的值( YES )..所以看起来Apple代码忽略值的设置如果有当前的音乐片段并且您的音乐没有改变代码..但确实注意到价值的变化。

This is all under iOS 3.0 . 这一切都在iOS 3.0下

Even in 2015, using iOS 8.2, this bug is still alive and kicking. 即使在2015年,使用iOS 8.2,这个bug仍然存在并且仍然存在。

Here's my solution, using XCode 6.2. 这是我的解决方案,使用XCode 6.2。

iPhone - phone goes to sleep even if idleTimerDisabled is YES iPhone - 即使idleTimerDisabled为YES,手机也会进入睡眠状态

Basically, even now, in 2015, the only way to safely make sure that the device doesn't go to sleep is to repeatedly call a piece of code to keep the device awake. 基本上,即使是现在,在2015年,安全地确保设备不进入睡眠状态的唯一方法是重复调用一段代码以使设备保持唤醒状态。

-(void)callEveryTwentySeconds
{
    //  DON'T let the device go to sleep during our sync
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}

听起来像一个bug,Radar文件 - 我并不感到惊讶,因为可能没有很多应用试图锁定屏幕播放音乐。

Having same issue. 有同样的问题。 It does work when the device is plugged in. You can press lock button on top, and my NSTimer fires later and causes a vibrate. 插入设备时它确实有效。您可以按顶部的锁定按钮,我的NSTimer稍后会触发并导致振动。 However if the device is not plugged in pressing the lock button puts the device to sleep. 但是,如果没有插入设备,按下锁定按钮会使设备进入睡眠状态。 Any solution would be greatly appreciated. 任何解决方案将不胜感激。

  • iCodeblog posted about the idletimer, I said it didn't work, and the person who develops 'cute clock' was nice enough to reply. iCodeblog发布了关于idletimer的消息,我说它不起作用,开发“可爱时钟”的人很好回复。 You have to do a hack, play a 1 second or longer silent sound every 10 or so seconds with NSTimer. 你需要做一个黑客,用NSTimer每10秒左右播放1秒或更长时间的静音。 This keeps the device awake even if the user hits the lock button. 即使用户按下锁定按钮,这也可以使设备保持唤醒状态。

I develop Seconds - Interval Timer for iPhone and iPod touch and I've had no end of trouble with this. 为iPhone和iPod touch开发了Seconds - Interval Timer ,我已经没有遇到麻烦了。 The idea of my app is that people create timers based on a number of intervals where each interval can have it's own playlist or track played. 我的应用程序的想法是人们根据许多间隔创建计时器,每个间隔可以拥有自己的播放列表或播放的曲目。

In iOS3 I had the problem that I couldn't disable the idle timer by just setting idleTimerDisabled = YES. 在iOS3中我遇到的问题是我无法通过设置idleTimerDisabled = YES来禁用空闲计时器。 In the end I came up with the same solution as Neil whereby I would periodically set it to NO, then immediately to YES again. 最后我想出了与Neil相同的解决方案,我会定期将其设置为NO,然后立即再次设置为YES。 This seemed to work. 这似乎有效。

I'm now updating the app to iOS4 (I know, iOS5 is just around the corner...) and now I have the opposite problem. 我现在正在将应用程序更新到iOS4(我知道,iOS5即将到来......)现在我遇到了相反的问题。 If the MPMediaPlayer changes track before the idle timer reaches it's limit it gets reset. 如果MPMediaPlayer在空闲计时器达到其限制之前更改了轨道,则它将被重置。 I've just tested this by creating an interval in my app that was 55 seconds, my auto-lock was set to a minute. 我刚刚在我的应用程序中创建了一个55秒的间隔,我的自动锁定设置为一分钟。 At 50 seconds the screen dimmed as it prepared to lock, but at 55 seconds when the music changed it went back to full brightness and then didn't lock as it should. 在50秒时,屏幕在准备锁定时变暗,但在音乐改变的55秒时,它恢复到全亮度,然后没有按原样锁定。

Overall, the implementation of this seems flakey at best. 总的来说,这一点的实施充其量只是好事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM