issues with retrievePeripheralsWithIdentifiers in ios13+

the following code retrieves my peripherals and allows connection in old verisons of IOS. Since Ios13 this method no longer works.. Specifically.


NSArray* knownPeripherals = [self.centralManager retrievePeripheralsWithIdentifiers:@[uuid]];


this does not find results, however under the same test scenrio it works on older devices . Below is the entire method. any ideas on why i can not get my peripheral would help.





self.discoveredPeripheralMap = [NSMutableDictionary new];

self.connectingPeripherals = [NSMutableArray new];

NSDictionary* centralOptions = @{ CBCentralManagerOptionRestoreIdentifierKey: CentralManagerIdentifier };

self.centralManager = [[CBCentralManager alloc] initWithDelegate:self

queue:nil

options:centralOptions];

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];

NSString* savedDeviceId = [defaults objectForKey:SavedBluetoothDeviceIdentifierKey];

if(savedDeviceId)

{

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:savedDeviceId];

//NSUUID* uuid = [NSUUID UUIDWithString:savedDeviceId];

NSArray* knownPeripherals = [self.centralManager retrievePeripheralsWithIdentifiers:@[uuid]];

if(knownPeripherals && knownPeripherals.count > 0)

{

CBPeripheral* peripheral = knownPeripherals[0];

_defaultPeripheral = [[DVBPeripheral alloc] initWithPeripheral:peripheral];

[self.discoveredPeripheralMap setObject:self.defaultPeripheral forKey:peripheral.name];

if(self.centralManager.state == CBCentralManagerStatePoweredOn)

{

[self connect:self.defaultPeripheral];

}

}

}

}

Accepted Reply

I can confirm this behaviour. I've just tested on an Apple iPhone 8 Plus running iOS 13.1.3. The call to retrievePeripheralsWithIdentifiers yields 'null'. If I'm running iOS 12, retrievePeripheralsWithIdentifiers behaves as expected.


I extended my info.plist with the key for 'NSBluetoothAlwaysUsageDescription' but this did not solve the issue.


EDIT: I could solve my issue. Please have a look at this blog post. Basically waiting until the cbCentralManager's state is PoweredOn is crucial under iOS 13. Hope this works for you, too!

Replies

I can confirm this behaviour. I've just tested on an Apple iPhone 8 Plus running iOS 13.1.3. The call to retrievePeripheralsWithIdentifiers yields 'null'. If I'm running iOS 12, retrievePeripheralsWithIdentifiers behaves as expected.


I extended my info.plist with the key for 'NSBluetoothAlwaysUsageDescription' but this did not solve the issue.


EDIT: I could solve my issue. Please have a look at this blog post. Basically waiting until the cbCentralManager's state is PoweredOn is crucial under iOS 13. Hope this works for you, too!

Thank you for your response, we were able to solve our issue using your post!