首先导入系统类库
//监听耳机事件
[[AVAudioSessionsharedInstance] setDelegate:self];
// Use this code instead to allow the app sound to continue to play when the screen is locked.
[[AVAudioSessionsharedInstance] setCategory:AVAudioSessionCategoryPlaybackerror:nil];
// Registers the audio route change listener callback function
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange,audioRouteChangeListenerCallback