With bluetooth-central UIBackgroundModes enabled iPhone is not discovering BLE device in background. not

bluetooth-central UIBackgroundModes is enabled.


As application goes to background calling

[centralManager scanForPeripheralsWithServices:[NSArray arrayWithObjects:[[NSUUID alloc] initWithUUIDString:SERVICE_UUID], nil] options:nil];


but no callback recieved for (waited for longer than 10 min also)

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI;


once un-lock the phone immediately get the didDiscoverPeripheral callback and the BLE device discovered.

Replies

If you are having difficulties discovering your peripheral when your app is in the background or the iOS device is locked, there are a number of things to check:

(not all of those will apply to your particular case, but these are good things to check for anyone having similar problems)

  1. - make sure in your code you are properly retaining your CoreBluetooth manager objects, and not inadvertently releasing them during the transition to background
  2. - if you are expecting your app to continue scanning for a peripheral for a long period after your app is backgrounded, do use CoreBlueooth preservation/restoration to allow iOS to continue scanning even after your app is removed from memory
  3. - make sure the advertising peripheral conforms with section 3.5 of Bluetooth Accessory Design Guidelines for Apple Products: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf


If you are getting the didDiscoverPeripheral callback as soon as you unlock the iOS device without launching your app, etc., number 3 above is the most likely culprit in your case.

Hello, I am facing a similar issue here.


Whenever my app scans the peripheral in background, it fires a local notification to notify me.

It is working well when screen is not locked, I got notification every few minutes.

But when screen is locked, nearly no local notificaiton is fired. (maybe once every half an hour).


You mentioned "If you are getting the didDiscoverPeripheral callback as soon as you unlock the iOS device without launching your app, etc., number 3 above is the most likely culprit in your case.". This is a really helpful information.

So does that mean the scanning intervals for iOS device are different in below scenairos?

1) app in background, screen not locked.

2) app in background, screen locked.

If the above is true, then I will reduce the advertising interval and try again.


Thank you.

Hi Marcoli,

How to scan the peripheral with particular advertisiment data and give local notification..I am not able to scan for the peripheral..

Can you help me in this flow


thanks in advance...