繁体   English   中英

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

[英]Getting MAC address of a bluetooth using BluetoothManager private framework

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

谢谢!

使用此代码:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM