views:

354

answers:

3

I've noticed that several iPhone apps, especially some more graphically intensive games take quite a while to exit when the home button is pressed.

My question is, weather it's possible to artificially recreate this situation, the reason being, that I'm trying to implement a sort of "phone protector" that starts making loud noises when some accelerometer data is read. The idea would be to have the AVAudioPlayer keep playing the sound for as long as possible (ie. until the iPhoneOS decides to kill the process for good).

I tried something like this in my app delegate, just to see how it reacts:

-(void)applicationWillTerminate:(UIApplication *)application{ 
    NSInteger i;
    while(true) {
     i++;
    }
}

What happens though, is that the home screen comes up immediately and the sound stops playing (the AVAudioPlayer instance is in a view controller), but the applications process is still in memory and in fact stops me from launching a new instance of the app until the old one is killed manually (this is all in the Simulator).

Any ideas?

+1  A: 
  1. You really need to test this on a real device.

  2. I have the feeling that you get 6 seconds to exit, after which you will be killed.

By the way, AVAudioPlayer, might be being a good citizen and getting out of the way. It does some strange and even annoying things under the hood. In this case you'll need something lower level, like a remote io audio unit. I know for a fact that if you don't stop this in applicationWillTerminate then it will happily go on making sound for a moment in the home screen.

Rhythmic Fistman
A: 

As it turns out, AVAudioPlayer doesn't actually behave like a good citizen, however I was using it's callback when finished playing to loop the sound, but for some reason that didn't work after applicationWillTerminate got called. Using numberOfLoops = -1 and adding an loop (i++; didn't work, NSLog(@"qwerty") did) to the app delegate did.

Funny enough, the sound actually continues to play forever. I'm using the official SDK, but with a jailbroken phone.

Weird. What OS? What about on non-jail broken phones?
Rhythmic Fistman
A: 

Unfortunately I couldn't associate the cookie based user I have at my work computer with my OpenID, so I couldn't reply properly.

Anyway, I'm using 3.0 and the same exact thing happens on both the simulator and the device. I can't test on a non-jail broken phone at the moment, because Apple is taking forever and then some to approve our license, even though we already have several apps coded and ready for launch...

I'll let you know as soon as I find out.

Joonas Trussmann