OC代码:
void ShowAlert()
{
AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
for (AVAudioSessionPortDescription* desc in [route outputs])
{
if ([[desc portType] isEqualToString:AVAudioSessionPortHeadphones])
{
printf("插着耳机");
}
else
{
printf("没有插着耳机");
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"连接耳机"
message:@"请连接耳机,减少噪音"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//响应事件