Skip to content

Instantly share code, notes, and snippets.

@liorazi
Created June 1, 2016 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liorazi/d16795ecbecd8e60bba0aeda5d8b7805 to your computer and use it in GitHub Desktop.
Save liorazi/d16795ecbecd8e60bba0aeda5d8b7805 to your computer and use it in GitHub Desktop.
Observing AVAudioSession Interruptions
- (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