iOS 5 deep sleep prevention

不问归期 提交于 2019-12-06 03:40:23

问题


I'm trying to build an alarm app that can fire an alarm while in locked-screen mode (the app is in the foreground, but the screen is locked). The alarm has to be triggered by a NSTimer not by uilocalnotification.

In iOS 4 I used the 'play silent sound every 10 seconds' hack to prevent the app from going to deep sleep and the timer events worked fine. However, in iOS 5 this doesn't seem to work.

Any ideas? Or this should work and I'm doing something wrong?


回答1:


It seems that you actually can use the 'play silent audio' hack in iOS 5, but the audio has to be audible meaning you can't play it at volume set to 0.0.




回答2:


You can use github.com/marcop/iPhoneInsomnia and set the volume to greater than 0, but it still doesn't work because the sound file is so short that the system kills your application before the timer is triggered and replays the sound. I solved this by setting the numberOfLoops of the audioPlayer to -1 (infinite repeat). Then it should work.

And you should also set the UIBackgroundMode plist key to an array of one string called "audio"




回答3:


It's probably a dirty workaround, but in the past I have used the proximity sensor to turn off the screen instead of locking the phone. Simply place the phone upside down and the screen will turn itself off.

[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];

This will allow you to retain full control over the device, while the screen does turn off.



来源:https://stackoverflow.com/questions/8561504/ios-5-deep-sleep-prevention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!