Why iOS app iBeacon wake up intervals varies?

Viewed 68

Hi i have a swift app that communicate with a BLE device with a beacon.

When i kill the app the beacon wake the app in background and it connect to the device and start communicating.

The interval of detection / connexion mostly take between 30 sec to up to 1 min after i kill the app. but sometime it take like 3 4 min.

Did anyone faced such issue and have an idea of whet could be happening it's the same process why it vary from time to time did it have a relation with the device itself ?

thx

1 Answers

Since iOS is closed source, it is impossible to say with certainty why delays in beacon detection happen. This is especially true in individual cases -- there are lots of variables.

However, we do have some ideas of how iOS CoreLocation manages to detect beacons based on reverse engineering, and I have some insight on based on building the Android Beacon Library which uses similar concepts.

Here is what we do know:

  • CoreLocation uses BLE hardware filters for pattern matching to get detections as quickly as possible. If a hardware filter slot is available, beacon monitoring will use the Bluetooth chip itself to look for a pattern first matching. This will give you a detection in less than a second when a beacon first appears.

  • In some cases hardware filters cannot be used (they are exhausted) or the beacon is known to be in the vicinity, so it is ignored. In these cases, a periodic backup scan is used to look for beacons.

  • The backup scan happens at different rates depending not the state of the phone and the beacon/bluetooth scanning state of apps running on the phone. If no apps are actively scanning and the screen is off, this can be every few minutes.

  • When the screen is turned on, it typically triggers a backup scan.

  • If your app is visible in the foreground and using ranging APIs or actively doing a BLE scan with CoreBluetooth, it is scanning at a 100% duty cycle.

  • In other cases, the duty cycle will be lower. If you are testing with a beacon that does not advertise frequently (e.g. less than the 10Hz in the iBeacon spec) it may miss detections at 10% duty cycle scan.

A few things to consider based on your description:

  1. You may have exhausted all of the BLE hardware filters on your phone, and your app may not be getting one. Unfortunately, this optimization is completely hidden, so there is no way to tell for sure. You can increase the chances of getting a hardware slot by uninstalling any apps you think may be scanning for Bluetooth, then uninstalling and reinstalling your app, and restarting the phone. If all else fails, do a factory reset on a test phone.

  2. Whenever you reboot your phone, it takes much longer for things to be fully booted than it appears. Location services are amongst the last things to be fully initialized. Always wait 5 minutes after reboot before doing any time-sensitive testing.

  3. It takes time for iOS to detect it is in an out of region state with a beacon. This is typically 30 seconds if the app is visible on the screen, but if it is not, it may take significantly longer because of the timing of backup scans. And you cannot get a new region entry event if iOS doesn't realize you have exited yet.

  4. If you kill your app when a beacon is visible (or when it had recently been visible) iOS may not know the in region / out of region state. If it thinks it is in region when it is not, it can take a long time to figure out it is out of region.

Related