Central Manager stops discover peripherals when device is locked

Hello everyone!


I have an app which must broadcast and detect iOS devices using Core Bluetooth Central and Peripheral managers.


It works pretty good in active mode Central Manager discover peripheral several times per second, in background mode (I have turned background modes for Central and Peripheral managers in Xcode settings) frequency of discovering became one time per two-three seconds.


But problem comes up when device screen became locked. In that case Central Manager stops calling didDiscoverPeripheral even if I specify service UUID.


Also, when screen unlocked Central Manager continue work in background mode.


So, my questions are:


  1. What sate obtain application when users press lock button?
  2. Is there any way to make Central Manager to discover or connect to devices using their service UUID's?
  3. Is there is something I missed to turn on to make Central Manager work in locked screen mode?
  4. Is there any way to force Central Manager work with locked screen as in background mode?

Some things are not clear in your question. Before I can answer

- are the devices you are trying to detect other iOS devices which are running an app to act like a peripheral?

- if so, are those app running in the foreground or background, and are those devices locked as well?

Let me clarify.


- Devices it am trying to detect are iOS devices which are running an app to act like a peripheral and central.

- App running foreground initially, but have support of background tasks for central and peripheral managers.

- Those devices are locked as well.


In general, devices must be locked and detect each other in this state using central manager to detect others and peripheral manager to broadcast itself.


Hope I was clear enough.

Unfortunately it is not possible for two iOS devices - one acting as central, and the other acting as peripheral - to detect each other while both apps are in the background or both devices are locked.


Without getting into the gritty of why this is not possible at the BLE level, power savings, etc., here is why CoreBluetooth won't allow you to do this:

- While in the background, a peripheral app cannot fully advertise - the peripheral name is stripped, and the service UUIDs are moved to an overflow area. Effectively the peripheral no longer advertises its service UUIDs.

- While in the background, a central app cannot scan for all devices, without specifying a service UUID to scan for. Therefore can only discover peripherals advertising those specific service UUIDs


So when both are in the background, one is looking for a service, but the other one is no longer advertising them in the standard location - and this creates an impass.


Therefore, what you are trying to do is not possible with CoreBluetooth.

I'm surprised to hear this.


The central-side restriction seems reasonable, but may I ask why this limitation is in place for the peripheral? It seems unduly restrictive, and there are presumably minimal power savings, since the peripheral can still advertise - just not effectively.


Beyond that, allowing devices to communicate in the background through BTLE seems like an important design goal. I can understand wanting to discourage an app from profligately attempting to communicate with all other iOS devices in the local area, but it still seems like there are a lot of scenarios for reasonable use.

I was under the impression that this should work if the Central Manager did in fact have the specific UUID to search. However, it does appear to be the case that if you have two iphones, and they are both locked, the Central Manager never does find the UUID (even as an overflow - though it is not clear how this actually works - the overflow is supposedly mechanized and should not have to be explicitly pulled). Is there another reason for this or is it a bug? This has been a question brewing online for about a year.


Bottom line questions:

1) Can one iphone running central manager on a locked screen scan for a specific UUID that is running on another iphone that is screen locked and acting as the peripheral manager advertising that UUID?

2) If so, can you link to a working example?

Hi Gualtier,


Actually this used to work in iOS8. Isn’t this a step back compared to iOS8?

With iOS8, two iPhones running an app acting like a Peripheral and Central could discover each other when at least one of the two devices had its screen on and not necessarily having the app in the foreground.


And btw, back at the time, we didn’t notice any impact on battery on iOS8 with the “enhanced discovery” capabilities. We did some battery measurements on iOS7 and iOS8 and found out that having BT ON vs. BT ON + having an app acting as a Central & Peripheral was the same! meaning that iOS was already very well optimized.


@Gualtier: any chance this gets back to what it used to be for next iOS release (iOS10?).

@All: there is another post on the exact same topic: https://forums.developer.apple.com/thread/19746

@All: i encourage you to submit through the bug report tool a “enhancement” request.

I am developing an enterprise application. This app is something that will be deployed to company enployees. so, if I'm creating an enterprise app, is there a way to advertise the discoverable info when in the background?


Given this is an enterprise app, the battery/security are not concerns for me.


Ravi

Central Manager stops discover peripherals when device is locked
 
 
Q