[英]How to set the name of BLE peripheral in iOS using Core Bluetooth
[英]Core bluetooth peripheral.name is nil
我只想列出附近蓝牙设备的名称。 但是, 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
回调中收到其专有名称- peripheral:didUpdateName:
。 假设不需要事先连接到外围设备,则应等待此回调并在回调代码中的mRemoteDevices
中更新适当设备的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.