Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone How to know if Bluetooth headset connected

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.

Thanks

like image 448
tech74 Avatar asked Feb 09 '10 18:02

tech74


1 Answers

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;
    }
like image 56
Pradip Sutariya Avatar answered Sep 22 '22 20:09

Pradip Sutariya