Connecting to multiple iBeacons at once

355 Views Asked by At

If i have a device acting as a receiver and it connects to an iBeacon, what would happen if it connected to another iBeacon whilst still processing the connection to the first (e.g. Hadn't finished the running the didEnterRegion method)? Does the framework automatically handle this and create another sort of 'instance' or could I run into problems?

Thanks

2

There are 2 best solutions below

2
On

If CoreLocation detects two different region entry events in quick succession, it is certainly possible that two threads will execute your delegate's didEnterRegion simultaneously. So, yes, you could run into problems.

For this reason, you should be careful to:

  1. Design your code in that method so that it will function properly if executed in simultaneous threads.

  2. Design your code in that method so it exits quickly. Any long-running processing should be done in a new thread.

While the question mentions "connected to another iBeacon", it is important to understand there is no actual connection -- beacons are transmit only devices, and iOS will passively look for them and send delegate callback methods based on starting to see them, or no longer seeing them.

0
On

I think that if they're all transmitting the same region (i.e. they all have the same proximity UUID) then CoreLocation won't keep sending the didEnterRegion and didExitRegion methods.

Once you start ranging for a region (that's a mouthful) the locationManager:didRangeBeacons:inRegion: method gets called repeatedly, which is where you can get the details of the connected beacons.