2012-05-16 82 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對象的這種屬性 –