1.首先导入头文件:
#import <AVFoundation/AVFoundation.h>
2.在该文件下存在监听事件名称,我们可以对该事件进行监听:
NSString *const AVAudioSessionRouteChangeNotification
3.使用通知中心设置监听:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(outputRouteChanged:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
4.实现监听触发事件:
- (void)outputRouteChanged:(NSNotification *)notification {
NSLog(@"---%@", notification.userInfo);
}
5.控制台打印结果为:
{
AVAudioSessionRouteChangePreviousRouteKey = "<AVAudioSessionRouteDescription: 0x17420ded0, \ninputs = (null); \noutputs = (\n \"<AVAudioSessionPortDescription: 0x17420dbc0, type = Headphones; name