[英]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.