0

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

Tom Cornish
  • 71
  • 1
  • 5
  • 1
    You shouldn't have any problems. I created a prototype game recently where I connected to 3 beacons at once. – Guy Kogus Nov 18 '14 at 15:19

2 Answers2

1

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.

Guy Kogus
  • 7,251
  • 1
  • 27
  • 32
1

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.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Hmm okay. How about if on device entry, i want the device to start it's own beacon with details dependant on the beacon, have it remain active for 30 seconds, then shut it down again. If the device come into range of another beacon, do you think it would handle starting a second beacon with different details? – Tom Cornish Nov 19 '14 at 13:13
  • 1
    iOS does not let you transmit two beacons simultaneously. If you start a second one, it disables the first. – davidgyoung Nov 19 '14 at 17:27