ios - 核心蓝牙 peripheral.name 为 nil

标签 ios objective-c core-bluetooth bluetooth-lowenergy

我只想获得附近蓝牙设备名称的列表。但是,peripheral.name 始终为 nil。广告包中的名称也始终为零。我附近有 7 台设备。我能看到他们,但看不到他们的名字。

我正在使用以下代码:

[self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]
                                            options:nil];


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

{

    NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);
    _discoveredPeripheral = peripheral;
    if(![self.mRemoteDevices containsObject:_discoveredPeripheral])
    {
        NSArray *peripherels = [self.centralManager retrievePeripheralsWithIdentifiers:@[_discoveredPeripheral.identifier]];
        [self.mRemoteDevices addObject:[peripherels objectAtIndex:0]];
        [self.mRemoteTable reloadData];
    }
    NSLog(@"retrieving peripherels: %@", self.mRemoteDevices);
}

最佳答案

确实经常发生在发现期间未解析外围设备名称的情况。然而,在你发现一个外围设备(并且可能连接到它,我不确定这是否真的有必要)之后,你很快就会在 CBPeripheralDelegate 回调 中收到它的正确名称 -外围设备:didUpdateName:。假设不需要事先连接到外围设备,您应该等待此回调并在回调代码中的 mRemoteDevices 中更新适当设备的名称。

关于ios - 核心蓝牙 peripheral.name 为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34488948/

相关文章:

ios - 修改过多字节的数据对象会导致 swift 应用程序崩溃

iphone - 用于长文本 + 选项的 IOS UI 元素

iphone - UIBarButtonItem中的按钮框架

ios - 如何在 Root View 中隐藏导航 Controller ?

ios - 如果我知道 iOS 中该 BLE 设备的 mac 地址,如何区分我应该连接哪个 BLE 设备的外围设备?

iphone - 手动调用 applicationDidEnterBackground

ios - ScrollView ios 8 Xcode 不滚动 - Swift

ios - 个人资料图片在 UITableViewCell 中被截断

ios - 我支持BLE 4.0的iOS设备是否可以连接所有支持BLE 4.0的设备?

android - 是否可以创建一个应用程序,安装后用户可以通过双击主页按钮轻松打开和关闭蓝牙/NFC?