4

I'm trying to implement device discovery using bluetooth in IOS 5.0.1 iPhone 4S. I'm using the private framework BluetoothManager.

My code is:

- (IBAction)searchForDevices:(id)sender
{
    [self.indicator setHidden:NO];


    [[NSNotificationCenter defaultCenter] addObserver:self    selector:@selector(bluetoothAvailabilityChanged:)     name:@"BluetoothAvailabilityChangedNotification" object:nil];

    btCont = [BluetoothManager sharedInstance];

    [[NSNotificationCenter defaultCenter] addObserver:self     selector:@selector(deviceDiscovered:) name:@"BluetoothDeviceDiscoveredNotification"     object:nil];
}

- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
    self.label.text = @"Availability changed!";
    [btCont setDeviceScanningEnabled:YES];
}

- (void)deviceDiscovered:(BluetoothDevice *)device
{

    [self.indicator setHidden:YES]; 
    self.label.text = device.address;

My bluetooth headset is discovered. deviceDiscovered callback function is called, but device.address does NOT contain the MAC address of the bluetooth device. The app is crashing. Also, device.name return the name of the notification (BluetoothDeviceDiscoveredNotification) instead of the name of the device discovered.

Any suggestions how can I retrieve the MAC address of my bluetooth headset this way?

Zoe
  • 27,060
  • 21
  • 118
  • 148
user-123
  • 874
  • 1
  • 13
  • 34

2 Answers2

1

use this code:

- (void)deviceDiscovered:(NSNotification *) notification {
    BluetoothDevice *bt = [notification object];
    NSLog(@"name: %@ address: %@",bt.name, bt.address);
lucianoenrico
  • 1,486
  • 1
  • 13
  • 21
0

If this is a jailbreak app, you can use the key kLockdownBluetoothAddressKey via liblockdown.dylib

skram
  • 5,314
  • 1
  • 22
  • 26
  • thanks for the response.. actually it is possible even easier because the object passed to deviceDiscovered IS actually a bluetooth device and it contains a name and mac address as well. I have written down my answer below. Is tere a way to know the RSSI though? This property does not exist in BluetoothDevice object – user-123 Jun 06 '12 at 11:52
  • Yes, but without the RSSI, it is of no value for my purpose. It is very strange there is no such property of BluetoothDevice object – user-123 Jul 17 '12 at 09:25