Apple explain AVAudioSessionInterruption
observer as a new method to handle interruptions. Apple explains it in Swift at this page but for someones that search for objective-c code this github issue must be useful.
You need to handle audio interrupts like
AVAudioSession *session = [AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(audioSessionInterruptionNotification:)
name:AVAudioSessionInterruptionNotification
object:session];
where your audio session interruption notification AVAudioSessionInterruptionNotification is something like
-(void)audioSessionInterruptionNotification:(NSNotification*)notification {
NSString* seccReason = @"";
//Check the type of notification, especially if you are sending multiple AVAudioSession events here
NSLog(@"Interruption notification name %@", notification.name);
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
seccReason = @"Interruption notification received";
//Check to see if it was a Begin interruption
if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
seccReason = @"Interruption began";
} else if([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeEnded]]){
seccReason = @"Interruption ended!";
//Resume your audio
}
}
}
You need to write your handling code then for interruption begin and end.