Found a solution! I had the same problem, my application resumed sound after interruption only if my application was open. When he was in the background, he was unable to resume the sound after the interruption.
I fixed this by adding the following lines of code:
Add this line when your application starts playing audio. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
And at the end of the Internet method, wait 1 or 2 seconds before resuming audio playback. This will allow the OS to stop using the audio channel.
- (void)endInterruptionWithFlags:(NSUInteger)flags { // Validate if there are flags available. if (flags) { // Validate if the audio session is active and immediately ready to be used. if (AVAudioSessionInterruptionFlags_ShouldResume) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue(), ^{ // Resume playing the audio. }); } } }
You can also add this line when your application stops (does not stop) while playing audio. But not required. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
source share