iBeacons and Core Location

Discussion in 'iOS Programming' started by mrTortex, Nov 22, 2013.

  1. mrTortex macrumors newbie

    Feb 12, 2011

    I have some questions I'm wondering if people can clarify?

    CoreLocation and iBeacons: am I correct in thinking a region is when we are talking to a beacon with a certain UUID? As we may have several beacons sharing that UUID, we are in a region if we are talking to any of those beacons? So a 'region' could be a shop or museum all sharing a unique UUID?

    Or is a region specific to each beacon?

    I'm wondering because I'm building a small test app with a couple of beacons, I want one beacon to show one view, a second beacon to show a second view - when proximity is immediate.

    At the moment I'm checking in the didRangeBeacons method, going through the array and calling a method which wants major, minor and proximity. I then run a conditional, if the major and minor plus proximity are what I expect run the segue. But I'm still ranging at this point so that function gets called every 200ms. If I stop ranging in that method I'll not know if I leave that proximity of that beacon.

    So at that point do I start checking for a proximity change not hat one beacon, and if that happens I start the process over?

    I can't find a clear explanation of this process.

  2. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia

    I've figured this out the hard way.

    The method to create a beacon region has 3 forms.


    The simplest form, initWithProximityUUID:, just takes a UUID. If you use that, any device advertising as an iBeacon with that UUID will trigger your beacon region "entered region" call.

    The next form, initWithProximityUUID:major:, takes a UUID and a major value. If you use that form, only beacons who match both the UUID and the major value will trigger a beacon entered event.

    The final form, initWithProximityUUID:major:minor:, takes a UUID, major AND minor value. If you use that, only beacons that match all those things trigger region notifications.

    If you use the UUID only method, then you do not get info about the major and minor IDs of the detected beacon(s) in your didEnterRegion/didExitRegion/didDetermineState calls. You only get major/minor data in the ranging calls.

    Be aware that things get tricky when you operate from the background. If you are monitoring for one or more beacons and the system detects a beacon that matches you will get a call from the background telling you about it. You will even get re-launched if your app was killed due to memory pressure.

    If you have ranging turned on, you'll then start to get a few seconds of ranging calls on the beacon(s) that are detected. However, if you decide (those beacons aren't close enough, I'm going to ignore for now) then you stop getting ranging notifications a few seconds later. By the time the user gets close enough, you aren't getting ranging info any more, so you completely miss it.

    The same goes for using multiple beacons with different major or major and minor region numbers as part of the same region. You only get the major/minor data that isn't explicitly set up for your region in the ranging calls. Thus, if you set up a region with only a UUID, and get a region entered even from the background, you can't tell what major/minor value the beacon has unless you turn on ranging. Then if you do turn on ranging, you only get a few seconds of data on the beacons that are in-range, before your app goes back to sleep. If the user enters the range of additional beacons in the same region that have different major/minor values, you never get notified about it.
  3. mrTortex thread starter macrumors newbie

    Feb 12, 2011
    Seems like Apple have some things to fix :)

    I'm writing my own Beacon Manager class currently to try to solve some of these issues, I'll share when it's complete.
  4. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    How are you doing that? Are you using lower level BLE APIs to implement the iBeacon APIs?

    I've been seriously thinking of doing the same thing, but have not found resources that I could use to get me started. Have you found good documentation/sample apps? If so, would you mind sharing?

    One thing you will not be able to do is collect iBeacon information when your app has been terminated due to memory pressure like Apple does. You should be able to have better background performance, but Apple has system-level support built into the OS that third party apps don't have access to.

Share This Page