一. 方式

1.注册监听

//注册监听耳机设备的插入/拔出

AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange,audioRouteChangeListenerCallback,  nil);

2.

二 .

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(outputDeviceChanged:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];

- (void)outputDeviceChanged:(NSNotification *)aNotification

{

BOOL flag = [AudioHelper hasHeadset];

if (flag) {

[MBProgressHUD showMessageHUDAddedTo:self.view message:@"设备已插入"];

}

else

{

[MBProgressHUD showMessageHUDAddedTo:self.view message:@"设备已拔出"];

}

}

05-08 08:43