-->

使用BluetoothManager私人框架蓝牙的获取MAC地址(Getting MAC addre

2019-09-17 06:18发布

我试图实现使用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地址?

谢谢!

Answer 1:

使用此代码:

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


Answer 2:

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



文章来源: Getting MAC address of a bluetooth using BluetoothManager private framework