我只想获得附近蓝牙设备名称的列表。但是,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/