I am having an issue updating my CoreBluetooth code from iOS 6 to iOS 7. I can scan for Peripherals and make connections, however, I am not able to reconnect a Peripheral using the new CoreBluetooth methods offered within iOS 7. Here is a look at how I am trying to accomplish the reconnection:
- (void)retrievePeripheral:(NSString *)uuidString
{
NSUUID *nsUUID = [[NSUUID UUID] initWithUUIDString:uuidString];
if(nsUUID)
{
NSArray *peripheralArray = [centralManager retrievePeripheralsWithIdentifiers:@[nsUUID]];
// Check for known Peripherals
if([peripheralArray count] > 0)
{
for(CBPeripheral *peripheral in peripheralArray)
{
NSLog(@"Connecting to Peripheral - %@", peripheral);
[self connectPeripheral:peripheral];
}
}
// There are no known Peripherals so we check for connected Peripherals if any
else
{
CBUUID *cbUUID = [CBUUID UUIDWithNSUUID:nsUUID];
NSArray *connectedPeripheralArray = [centralManager retrieveConnectedPeripheralsWithServices:@[cbUUID]];
// If there are connected Peripherals
if([connectedPeripheralArray count] > 0)
{
for(CBPeripheral *peripheral in connectedPeripheralArray)
{
NSLog(@"Connecting to Peripheral - %@", peripheral);
[self connectPeripheral:peripheral];
}
}
// Else there are no available Peripherals
else
{
// No Dice!
NSLog(@"There are no available Peripherals");
}
}
}
}
Where uuidString is the saved Peripheral UUID.
I am always getting to the NSLog statement where there are no available Peripherals. I suppose I am missing something very obvious and someone can point me in the right direction.
In addition, I have read other posts about the iOS 7 update issues with CoreBluetooth and have tried reseting the BLE device and the iOS device but to no avail.
Thanks in Advance! audible