【问题标题】:Getting MAC address of a bluetooth using BluetoothManager private framework使用 BluetoothManager 私有框架获取蓝牙的 MAC 地址
【发布时间】:2012-05-16 06:19:54
【问题描述】:

我正在尝试在 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 地址吗?

【问题讨论】:

    标签: ios iphone bluetooth iphone-privateapi


    【解决方案1】:

    使用此代码:

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

    【讨论】:

    • 谢谢,RSSI 呢?如何找到发现的蓝牙设备的 RSSI?
    【解决方案2】:

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

    【讨论】:

    • 感谢您的回复。实际上它可能更容易,因为传递给 deviceDiscovered 的对象实际上是一个蓝牙设备,它还包含名称和 MAC 地址。我已经在下面写下了我的答案。有办法知道RSSI吗? BluetoothDevice 对象中不存在此属性
    • 是的,但是没有 RSSI,它对我的​​目的毫无价值。很奇怪蓝牙设备对象没有这样的属性
    猜你喜欢
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    相关资源
    最近更新 更多