开发者

Iphone How to know if Bluetooth headset connected

using iphone sdk 3.1.2.

Is there anyway of knowing if a Bluetoo开发者_JS百科th 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.

Thanks


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

First import this framework #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;
    }


Have you looked at the: kAudioSessionProperty_AudioRoute?

Also see this post:

How can I find out if an external headset is connected to an iPhone?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜