I'm Having an issue with Core Bluetooth under iOS. I'm programming an OTA updater, and running into a strange issue. When I switch the device into OTAU mode it disconnects and advertises different services under the same device UUID, problem is, when I try to find services from the newly connected device I'm given the old list of services, which are no longer valid. A telling part of the problem is that the CBPeripheral.name value is the original device name, but in the advertising dictionary returned to didDiscoverPeripheral it is the correct, new name.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
for (id key in advertisementData) {
NSLog(@"key: %@, value: %@ \n", key, [advertisementData objectForKey:key]);
}
NSLog(@"Discovered peripheral with identifer: %@, state: %d, name: %@, services: %@",
[peripheral identifier],
[peripheral state],
[peripheral name],
[peripheral services]);
if (!self.peripherals)
self.peripherals = [[NSMutableArray alloc] initWithObjects:peripheral,nil];
else
{
for(int i = 0; i < self.peripherals.count; i++)
{
CBPeripheral *p = [self.peripherals objectAtIndex:i];
if ((p.identifier == NULL) || (peripheral.identifier == NULL))
continue;
if ([self UUIDSAreEqual:p.identifier UUID2:peripheral.identifier])
{
[self.peripherals replaceObjectAtIndex:i withObject:peripheral];
NSLog(@"Duplicate UUID found updating...");
return;
}
}
peripheral.delegate = self;
[self.peripherals addObject:peripheral];
NSLog(@"New UUID, adding");
}
}
Here's what I see back:
key: kCBAdvDataChannel, value: 38
key: kCBAdvDataLocalName, value: Xxxx1000_boot
key: kCBAdvDataIsConnectable, value: 1
Discovered peripheral with identifer: <__NSConcreteUUID 0x156787d0> 9E7A4F82-29F2-08EF-F6A5-9ADCC0790B7F, state: 0, name: Xxxx1000, services: (null)
often, for the next clean run of the program it will show the other way around with the Xxxx_boot for the peripheral name and Xxxx for the advertised name (advertising always correct).
I don't know of any way to clear peripheral information saved within CBCentralManager, I've even tried creating a new instance of the CentralManager, but nothing seems to work. Any ideas?