I just want to have the list of nearby Bluetooth devices' names. However, peripheral.name
is always nil. The name in Advertising package is also always nil. I have 7 devices nearby. I can see them but not their names.
I am using following code:
[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);
}
It often happens indeed that the peripheral names are not resolved during discovery. However, after you've discovered a peripheral (and maybe connected to it, I'm not sure if this is truly necessary), you'll soon receive its proper name in CBPeripheralDelegate
callback - peripheral:didUpdateName:
. Assuming that prior connection to the peripheral is not necessary, you should just wait for this callback and update the name of a proper device in your mRemoteDevices
in the callback code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.