mm24
mm24

Reputation: 9616

What happens in iOS stop monitoring for beacon region? How can we get iOS create more subsequent didEnterRegion events?

I am playing with iBeacon and I find it frustrating that whenever we are inside a beacon region and then we go outside it can take up to 15 minutes until the phone detects the "Exit event".

In order to overcome this I am considering stopping the beacon monitoring as soon as we enter (by calling stopMonitoringForRegion on CLLocationManager).

However I tried and it does not seem to work.

This is what I think iOS does:

iOS region table:

App1: UUIDx1
App1: UUIDx2
..
App1: UUIDx20 (Maximum)
App2: UUIDy1
App3: UUIDz1
App3: UUIDz2

When we stop monitoring a region I except iOS to remove the corresponding UUID from the internal scan table. However this does not seem to stop iOS waiting (up to 15 minutes) before realising that it did exit the region.

Has anyone dealt with this before?

How can we program iOS and the app to create subsequent didEnterRegion events (even within 15 minutes)?

Upvotes: 0

Views: 306

Answers (1)

davidgyoung
davidgyoung

Reputation: 65025

Two tips:

  1. When your app is in the foreground, you can accelerate both region entry and exit events by ranging for your region at the same time as monitoring. Ranging will ensure that bluetooth scans go on continually while your app is in the foreground. This will make entries happen within a second of beacon detection and exits happen within a few seconds of the beacon no longer being seen.

  2. For best results, install as few beacon apps as possible, monitor for as few regions as possible. While not published information, evidence suggests that iOS attempts to speed up detections based on hardware assist. Bluetooth chips let you set up hardware filters for byte patterns of bluetooth packets you are interested in, but they have a limited number of slots. The first regions (30?) to be registered for monitoring on an iOS device will get these hardware assist slots. Regions that are set up for monitoring later may not get these slots, forcing CoreLocation to fall back to full bluetooth scanning. If ranging is active for an app in the foreground, these scans go on continually, giving fast results. If ranging is not active, then iOS will do a periodic background scan, typically every 15 minutes.

Upvotes: 1

Related Questions