ios - 使用 BluetoothManager 私有(private)框架获取蓝牙的 MAC 地址

标签 ios iphone bluetooth iphone-privateapi

我正在尝试在 IOS 5.0.1 iPhone 4S 中使用蓝牙实现设备发现。 我正在使用私有(private)框架 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);

关于ios - 使用 BluetoothManager 私有(private)框架获取蓝牙的 MAC 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10613036/

相关文章:

ios - 通过触摸选择行在表格 View 单元格中预览 View

ios - iPhone 5 屏幕在横向比例时系统说它不是横向

android - 使用 adb 查找设备蓝牙 MAC 地址

ios - 为什么我在 Swift 中收到多个 UILocalNotifications?

ios - 如何使用行距准确获取 UILabel 的高度?

ios - 多点连接范围?

iphone - UITabBarController 自定义

iphone - UIColor 到无符号整数

android - 是否可以从已经为特殊应用程序配置的 BT 设备获取蓝牙数据?

android - 如何使用蓝牙从arduino接收串行数据?