2012-05-16 85 views
4

我试图在iOS 5.0.1 iPhone 4S中使用蓝牙实现设备发现。 我正在使用私人框架BluetoothManager。使用BluetoothManager私有框架获取蓝牙的MAC地址

我的代码是:

- (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; 

我的蓝牙耳机发现。 deviceDiscovered回调函数被调用, 但device.address不包含蓝牙设备的MAC地址。该应用程序崩溃。 此外,device.name返回通知的名称(BluetoothDeviceDiscoveredNotification)而不是发现的设备的名称。

任何建议如何以这种方式检索我的蓝牙耳机的MAC地址?

谢谢!

回答

1

使用此代码使用的关键kLockdownBluetoothAddressKey

- (void)deviceDiscovered:(NSNotification *) notification { 
    BluetoothDevice *bt = [notification object]; 
    NSLog(@"name: %@ address: %@",bt.name, bt.address); 
+0

谢谢,RSSI呢?如何找到发现的蓝牙设备的RSSI? –

0

如果这是一个越狱的应用程序,你可以通过liblockdown.dylib

+0

感谢您的答复..实际上它是可能的,即使因为对象更容易传递给deviceDiscovered IS实际上是一个蓝牙设备,它也包含一个名称和mac地址。我在下面写下了我的答案。虽然知道RSSI的方法是? BluetoothDevice对象中不存在此属性 –

+0

您是否设法读取名称? – radhoo

+0

是的,但没有RSSI,它对我的​​目的没有任何价值。很奇怪,没有BluetoothDevice对象的这种属性 –