My code is below and the success variables are always YES.
- (void)handleAudioSessionInterruption:(NSNotification *)notification
{
NSInteger interruptionType = [notification.userInfo[AVAudioSessionInterruptionTypeKey]integerValue];
NSError *error;
if (interruptionType == AVAudioSessionInterruptionTypeBegan)
{
//Interruption began, so we should stop audiosession
BOOL success = [[AVAudioSession sharedInstance]setActive:NO error:&error];
NSLog(@"Interruption began, session ended: %d", success);
}
else if (interruptionType == AVAudioSessionInterruptionTypeEnded)
{
//Interruption ended, so we should restart audiosession
BOOL success = [[AVAudioSession sharedInstance]setActive:YES error:&error];
NSLog(@"Interruption ended, session began: %d", success);
}
NSLog(@"got an error: %@", error);
}