Created
June 1, 2016 08:57
-
-
Save liorazi/d16795ecbecd8e60bba0aeda5d8b7805 to your computer and use it in GitHub Desktop.
Observing AVAudioSession Interruptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)addInterruptionNotification { | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:@"AVAudioSessionInterruptionNotification" object:nil]; | |
} | |
- (void)handleInterruption:(NSNotification *) notification{ | |
if (notification.name != AVAudioSessionInterruptionNotification || notification.userInfo == nil) { | |
return; | |
} | |
NSDictionary *info = notification.userInfo; | |
if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) { | |
if ([[info valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) { | |
NSLog(@"InterruptionTypeBegan"); | |
//Do something when interruption begins | |
} else { | |
NSLog(@"InterruptionTypeEnded"); | |
//Do something when interruption ends | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment