Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 deep sleep prevention

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?

like image 578
Peter Sarnowski Avatar asked Dec 19 '11 12:12

Peter Sarnowski


2 Answers

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.

like image 83
Peter Sarnowski Avatar answered Oct 03 '22 01:10

Peter Sarnowski


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"

like image 24
Anton Holmberg Avatar answered Oct 03 '22 02:10

Anton Holmberg