iOS电话等中断事件的开始和结束通知
#import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruptNoti:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; } //音频播放中断的通知 -(void)handleAudioSessionInterruptNoti:(NSNotification*)noti { NSDictionary *userInfo = noti.userInfo; AVAudioSessionInterruptionType type = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue]; switch (type) { case AVAudioSessionInterruptionTypeBegan: { //需要停止播放操作 } break; case AVAudioSessionInterruptionTypeEnded: { AVAudioSessionInterruptionOptions options = [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue]; if (options == AVAudioSessionInterruptionOptionShouldResume) { //需要执行播放操作 } } break; default: break; } }