Reputation: 395
The following code should play a silent audio clip on a loop to keep an application active in the background:
//set sessions ....
.........
//play
audio_player = [[AVAudioPlayer alloc] initWithContentsOfURL: url error:NULL];
audio_player.numberOfLoops= -1; //always repeat
bool ret = [audio_player play];
You press the home button and it plays in background, keeping your application active.
However, when you make a phone call, the player will stop and [audio_player play]
will return false after that.
So the question is, when in the background, how do you prevent AVAudioPlayer's playback from being interrupted or allow it to resume when interrupted? Otherwise, the application will terminate 10 minutes after the silent audio loop has last played.
I know there is a solution, because there are many alarm clock apps that can run in the background without being affected. I have tested and they are really running in the background.
Can anyone come up with a solution to run in the background without being rejected by the App Store?
Upvotes: 2
Views: 1649
Reputation: 4296
The answer is once your app is in the background you can not open the audio device again until your app returns to the foreground.
Upvotes: 1