BLE Scanning stops when phone is in locked mode

I have a solution where my application should scan the Bluetooth enabled Beacon devices in the foreground, background, locked mode for the iphone.

Currently we have built the project, which is working fine in foreground mode. We have tried exploring multiple options to enable the feature in background and locked mode.

As of now, we have come up with the solution which implements Picture in Picture mode in the application and once the application is minimized. The PIP window opens which solves our problem. But the problem stays with locked mode. The scanning is not working in locked mode.

So can we know how the bluetooth scanning will work in background and locked mode. Please also mention the alternative solutions to the problem statement if background and locked mode scanning is not possible.

I have attached the project source code for reference.

This project is being built for Google, so it is bit urgent.

Can I expect a quick response to this query?

Answered by Engineer in 804404022

Depending on what your expectations are from the scanning and what the specifics are on the "Beacon device" you could be running into one or more of the following challenges when the app is not in the foreground:

1- if the device is an iBeacon device and you are using CoreLocation to scan instead of CoreBluetooth, you have to make sure the beacon device is 100% compatible with the iBeacon specs. Any variation will cause issues

2- for CoreBluetooth scanning, if you are expecting to see multiple advertisements in the background, this will not work, as apps in the background will only receive a single advertisement notification for each beacon device

3- if you are not able to receive any advertisements when in the background (rather than only one) then your beacon device may not be advertising properly. Please consult Accessory Design Guidelines for Apple Devices for the advertisement requirements for successful discovery

4- if you are receiving at least one advertisement, but not finding the data you are looking for, it could be that the data you are looking for is in the secondary advertisement packet (SCAN_RSP) which may be ignored when your app is not in the foreground.

If you can elaborate on what you are doing and what exact issue is, I can explain further and suggest workarounds if possible.


Argun Tekant /  DTS Engineer / Core Technologies

Accepted Answer

Depending on what your expectations are from the scanning and what the specifics are on the "Beacon device" you could be running into one or more of the following challenges when the app is not in the foreground:

1- if the device is an iBeacon device and you are using CoreLocation to scan instead of CoreBluetooth, you have to make sure the beacon device is 100% compatible with the iBeacon specs. Any variation will cause issues

2- for CoreBluetooth scanning, if you are expecting to see multiple advertisements in the background, this will not work, as apps in the background will only receive a single advertisement notification for each beacon device

3- if you are not able to receive any advertisements when in the background (rather than only one) then your beacon device may not be advertising properly. Please consult Accessory Design Guidelines for Apple Devices for the advertisement requirements for successful discovery

4- if you are receiving at least one advertisement, but not finding the data you are looking for, it could be that the data you are looking for is in the secondary advertisement packet (SCAN_RSP) which may be ignored when your app is not in the foreground.

If you can elaborate on what you are doing and what exact issue is, I can explain further and suggest workarounds if possible.


Argun Tekant /  DTS Engineer / Core Technologies

  1. Our device is not an iBeacon device. It is a BLE Beacon Device.
  2. We are using CoreBluetooth in our application, we are expecting to see multiple advertisement packets which should contain manufacturing data of the device in background and locked mode. Currently we are getting manufacturing data in foreground.
  3. We are receiving manufacturing data in background just for 2-3 seconds after putting it in background/Locked mode. Also in Background we are getting characteristics data for single device.
  4. We are receiving characteristics data in background/locked mode which is not the data we are looking for, we need manufacturing data of the beacon device in background/Locked mode.

We have put an email with same query, where we have got below reply. Pls consider that too while providing a solution.

Please include the line below in follow-up emails for this request.

Case-ID: 9114422

The actual answer depends on exactly what you mean by "scan not working" and what actually is happening with the scans, but in general when an app is in the background and/or the device is locked, Bluetooth scanning becomes very limited.

If I understand your use case correctly, you are trying to read the manufacturer data from the advertising packets, which I presume is sending you some data that changes from packet to packet. This is not going to work unless your app is in the foreground.

While foreground apps can detect every advertising packet, once they stop being active, they will be sent only ONE advertisement packet/data per device per scan.

So, if you are trying to read changing data from advertisements, this will not work in the background. Your only option here is going to be to connect to the peripheral and have it write the changing data to a characteristic, from which your app will then read the data.

BLE Scanning stops when phone is in locked mode
 
 
Q