Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitoring iBeacon beacons in background

I've been developing an iOS app and playing around with Apple's CoreLocation and iBeacon technology. So far I used three beacons with different UUIDs. Everything was ok until I decided to add more beacons to my app. Only then I ran into strange issue. It's been said, a single app can monitor up to 20 beacon regions at once, when in the background - however in my particular case, this number seems to be 3. I tried different approaches, nothing worked. When I shuffled beacons in their array the outcome was as I expected - only the first 3 beacon regions triggered didEnterRegion and didExitRegion events when app was in background. This didn't applied when it was in foreground.

Please consider this:

  1. I have an array of custom beacon objects (consumed from API)
  2. For each custom beacon object I create an instance of CLBeaconRegion like so:

    let beaconRegion = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: region.uuid)!, identifier: region.uuid)
    
    beaconRegion.notifyOnEntry = true
    beaconRegion.notifyOnExit = true
    beaconRegion.notifyEntryStateOnDisplay = true
    
  3. Then I pass that instance to CLLocationManager's startMonitoringForRegion method like so:

    locationManager.startMonitoringForRegion(beaconRegion)

When looping through CLLocationManager's monitoredRegions method response I get all the beacon regions I expected with regionState 2 (outside)

  1. On top of that I've already added:

    NSLocationAlwaysUsageDescription

to app's Info.plist

locationManager.requestAlwaysAuthorization()

to ViewController's viewDidLoad method

Still, didEnterRegion and didExitRegion trigger only when I'm in range of any of the first three beacon regions I started monitoring for.

Thanks,

Piotr Czarnoleski

like image 389
Piotr Czarnołęski Avatar asked Jul 19 '16 14:07

Piotr Czarnołęski


People also ask

What is iBeacon detection?

An iBeacon is a device that emits a Bluetooth signal that can be detected by your devices. Companies can deploy iBeacon devices in environments where proximity detection is a benefit to users, and apps can use the proximity of beacons to determine an appropriate course of action.

How accurate is iBeacon?

We implemented this fusion workflow in an Android smartphone and conducted real-time experiments in a building floor. Two different routes with sharp turns were selected. The positioning accuracy of the iBeacon-based method is RMSE 2.75 m.

How do I find iBeacons?

Identifying iBeacons To identify each iBeacon, an iBeacon is identified using three numbers: Proximity UUID (16-bytes), Major (2 bytes), and Minor (2 bytes) (see Figure 1). Figure 1: Three numbers are used to identify an iBeacon . The assignment of these three numbers is totally up to the implementers.

Do you need an app for iBeacon?

Summary: For installations with regular beacons (an iBeacon is a type of beacon) then you cannot do much without an app, as you cannot interact with users (even after the additions from Eddystone).


1 Answers

An iOS device has a limited number of hardware acceleration slots for beacon detection. These slots defer to the bluetooth chip to notify the operating system when a beacon region pattern has been matched. When these slots are used, background detections are very quick -- a region entry event can happen within a second or two of the beacon transmission being in range.

If these slots run out, however, then the operating system must fall back to full scans to find the remaining regions. The operating system throttles these to save battery. Evidence suggests that they take place about every 15 minutes. This means that if any regions monitored by your app that don't get a hardware acceleration slot can take up to 15 minutes to be detected after a matching beacon comes into range (although on average it will often take less time -- 7.5 minutes would be the average)

How many hardware slots are available? This is undocumented and may vary by iOS device model. But experimentation shows it may be about 30. This is across all apps on the phone and is completely unrelated to the 20 region limit per app. The first apps to register regions are the first apps to get the slots.

Read more here: https://developer.radiusnetworks.com/2015/04/21/max-beacon-regions-ios.html

It is possible that the above is what you are experiencing, and there are only 3 hardware acceleration slots left on your phone for your app. To test this theory, you can:

  1. Uninstall other apps that you expect may be registering beacon regions, which should free up more slots.
  2. Wait up to 15 minutes to see if you get detections for the other regions in the background.
like image 189
davidgyoung Avatar answered Sep 25 '22 00:09

davidgyoung