iPhone如何知道是否连接了蓝牙耳机 [英] Iphone How to know if Bluetooth headset connected

查看:1513
本文介绍了iPhone如何知道是否连接了蓝牙耳机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iphone sdk 3.1.2.

using iphone sdk 3.1.2.

是否知道蓝牙耳机是否已连接到设备?不需要任何信息,除非已连接.这与通过音频会话的属性侦听器知道是否插入了一个插件不同.

Is there anyway of knowing if a Bluetooth headset is connected to the device? Don't need any info except if its connected or not. This is different from knowing if one was plugged in or not which one can do via a Property Listener of an Audio Session.

谢谢

推荐答案

调用此方法以查找蓝牙耳机是否已连接.

Call this method to find out the bluetooth headset is connected or not.

首先导入此框架#import <AVFoundation/AVFoundation.h>

- (BOOL) isBluetoothHeadsetConnected
    {
        AVAudioSession *session = [AVAudioSession sharedInstance];
        AVAudioSessionRouteDescription *routeDescription = [session currentRoute];

        NSLog(@"Current Routes : %@", routeDescription);

        if (routeDescription)
        {
            NSArray *outputs = [routeDescription outputs];

            if (outputs && [outputs count] > 0)
            {
                AVAudioSessionPortDescription *portDescription = [outputs objectAtIndex:0];
                NSString *portType = [portDescription portType];

                NSLog(@"dataSourceName : %@", portType);

                if (portType && [portType isEqualToString:@"BluetoothA2DPOutput"])
                {
                    return YES;
                }
            }
        }

        return NO;
    }

这篇关于iPhone如何知道是否连接了蓝牙耳机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆