5

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?

F'x
  • 12,105
  • 7
  • 71
  • 123
Peter Sarnowski
  • 11,900
  • 5
  • 36
  • 33

3 Answers3

4

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.

Peter Sarnowski
  • 11,900
  • 5
  • 36
  • 33
4

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"

Anton Holmberg
  • 1,113
  • 12
  • 15
2

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.

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105