views:

320

answers:

3

Hi there.

I want my app (LaunchDaemon) to keep running even if user locks the iPhone. My LaunchDaemon simply check a file and if some condition is true, it displays an Alert to the User. Its working great when iPhone is on Home Screen, but it is not working when user Locks the Screen.

I want something Similar to Alarm app of iPhone which will show an Alert even if the iPhone screen is Locked.

Any suggestions on how to do this? BTW i am developing for JB iPhone.

+1  A: 

OS powers down the device and suspends your app after about 30 seconds after screen is locked. However, if your app is playing a sound OS will not do that. Hence what you need to do is play a silent sound in a loop.

DenNukem
Playing silent sound in a loop will drain the battery right? Is it safe to do this?
raziiq
A: 

i did what you said. I used a silent sound and playing it in a loop using the code below.

    NSString *pathForSilentFile = [[NSBundle mainBundle] pathForResource:@"noSound" ofType:@"wav"];
NSURL *soundFile = [[NSURL alloc] initFileURLWithPath:pathForSilentFile];
AVAudioPlayer *silentPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:NULL];
[soundFile release];
[silentPlayer prepareToPlay];
[silentPlayer setVolume:0.0];
silentPlayer.numberOfLoops = -1;

[silentPlayer play];

But still after the iphone is locked, my app doesnt show an alart. Please keep in mind that i am talking about a LaunchDaemon. All the functionality is taking place in a LaunchDaemon. The code given above is also from the LaunchDaemon.

Any Suggestions on this??

raziiq
+1  A: 

Alright i have solved this problem too.

Here is a very good tutorial on how to prevent deep sleep of iPhone.

Prevent iPhone Deep Sleep

It took me quite sometime to made this work, as NSRunLoop was not running for me automatically.

Hope this will help someone else also.

Best of Luck !!!

raziiq