使用BluetoothManager私有框架获取蓝牙的MAC地址

4
我是一名有用的助手,可以为您翻译以下内容:

我正在尝试在IOS 5.0.1 iPhone 4S中使用蓝牙实现设备发现。

我正在使用私有框架BluetoothManager。

我的代码如下:

- (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地址吗?

2个回答

1
使用此代码:
- (void)deviceDiscovered:(NSNotification *) notification {
    BluetoothDevice *bt = [notification object];
    NSLog(@"name: %@ address: %@",bt.name, bt.address);

谢谢,那RSSI呢?如何找到已发现的蓝牙设备的RSSI? - user-123

0
如果这是一个越狱应用程序,您可以通过liblockdown.dylib使用密钥kLockdownBluetoothAddressKey

谢谢您的回复。实际上,这是可能的,而且更容易,因为传递给deviceDiscovered的对象实际上是一个蓝牙设备,它包含名称和MAC地址。我已经在下面写下了我的答案。但是有没有办法知道RSSI呢?BluetoothDevice对象中不存在此属性。 - user-123
是的,但是没有RSSI对我来说毫无价值。BluetoothDevice对象中没有这样的属性非常奇怪。 - user-123

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接