How to obtain Location Services authorization for iBeacon on iOS?

Follow

With iOS 8, Apple introduced changes to it's Location Services authorization model. Those changes affect every app using iBeacon. Beacon-enabled apps no longer require the Background App Refresh, but they need to ask for one of the permission types to access location data.

Location Services permissions:

  • always authorization - the app can access location data when it's visible on the screen, but is also given access to a certain subset of these when in the background or even when terminated
  • when in use authorization - the app can access location data only when it's visible on the screen
  • denied - the app can't access location data at all

How does it affect Ranging and Monitoring?

With always authorization, you can use Ranging in the foreground and region Monitoring when in the foreground and background. Even if your app is killed while monitoring, it'll still be relaunched by iOS to handle incoming monitoring events.

With when in use authorization, you can use Ranging in the foreground, but you won't be able to start Monitoring at all - not even in the foreground!

When denied access to Location Services, your app won't be able to range or monitor for beacons.

What does all of this mean for my app?

In order to use Ranging and Monitoring, you need to obtain appropriate permission to access Location Services - when in use for Ranging and always for Monitoring.

  1. Add a mandatory description of how your app uses Location Services

You can do that by navigating to your Info.plist file in the Project Navigator (it's in the Supporting Files directory), right-clicking on it and selecting Open As - Source Code, and adding the following code just before the </dict> line:


For when in use authorization:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This application uses your location to determine which table you're at when ordering your coffee.</string>

For always authorization:

<key>NSLocationAlwaysUsageDescription</key>
<string>This application monitors your location to show you promotional offers in shops you're passing by.</string>
  1. Request appropriate permission

Before you start using beacon ranging or monitoring, you're required to call one of the following

ESTBeaconManager methods:

  • requestWhenInUseAuthorization
  • requestAlwaysAuthorization

If your application is doing this for the first time, the user will see a pop-up notification asking them to allow the app to access their location. This pop-up will contain the UsageDescription you provided in the Info.plist file.

Once the user grants or denies the permission, subsequent calls to requestWhenInUseAuthorization or requestAlwaysAuthorization will not present any more pop-ups. To change the permission, direct your users to the Settings app. Note that it is still mandatory to call either requestWhenInUseAuthorization or requestAlwaysAuthorization before starting Ranging or Monitoring - even if your app was already granted the permission and no pop-up is going to be displayed!

  1. Determine if your app has been granted the requested permission

If your app does not have the appropriate permission to use Ranging or Monitoring, no error will be reported - your ESTBeaconManagerDelegate will simply not be getting any location updates, such as didRangeBeaconsInRegion or didEnterRegion.

It’s a good practice to make sure your app was granted necessary permission to use Location Services and modify its behavior if the user chose to deny such access.

You can monitor the authorization status in two ways:

  • By calling the ESTBeaconManager's authorizationStatus class method and checking the CLAuthorizationStatus value returned.
  • By implementing the beaconManager:didChangeAuthorizationStatus: delegate method and listening for changes in the authorization status.

For more details, feel free to consult Apple's official CoreLocation documentation.

How does this affect Estimote SDK?

Only Core Location-based methods are affected. For a full list of such methods, take a look at our iOS API reference.

None of the above applies to Core Bluetooth-based methods. For example, startEstimoteBeaconsDiscoveryForRegion is a Core Bluetooth-based scan and does not fall under Location Services authorization model. You can use this scan when your app is in the foreground – and in the background, provided you have the Bluetooth-central background mode enabled.

Was this article helpful?
4 out of 4 found this helpful

14 Comment(s)

  • Avatar
    Maël Frize

    Thanks for sharing this article and your blog post about lock screen notifications, Piotr.

    We are using background beacon monitoring in our apps. Some of our customers complained that the location arrow in the status bar won’t disappear after killing the apps manually. Technically, the location arrow makes sense since the OS is still supposed to monitor on the killed apps behalf.

    However, this behaviour confuses some users. They want the location arrow to disappear after killing the app.

    Do you have any ideas for a workaround?

  • Avatar
    Wojtek Borowicz

    Hi Mael,

    If you want to be monitoring for the beacons in the background, then you need to grant always authorization, and then the arrow will always be visible. If you want it visible only if the app is active, then you can grant when in use authorization, but you won't be able to perform monitoring at all.

    Regards,

  • Avatar
    Il Cato

    Is anyone aware of the algorithm behind the lock screen notification icon for the app suggestion feature that is not based on iBeacon?

  • Avatar
    Saikrishna Jonnala

    when ios app is terminated, is it possible for local beacon notifications in iOS 8 ?

  • Avatar
    Wojtek Borowicz

    Hi there,

    @Il Cato: lock screen suggested apps with beacons are only supported if you're using the iBeacon standard.

    @Saikrishna: yes, it is. We have a tutorial for that right here: https://community.estimote.com/hc/en-us/articles/203253193-Launching-notifications-in-iOS-when-the-app-is-killed

    Cheers.

  • Avatar
    Il Cato

    @Wojtek, I'm referring to suggested apps on lock screen even when app is not installed (e.g.: Starbucks, Ikea apps).

  • Avatar
    Wojtek Borowicz

    Hi,

    Suggested Apps will work with iBeacon only if the app is installed. You might prompt user to download it with GPS geofencing.

    Cheers.

  • Avatar
    Gabriele Ciaravolo

    Hi everyone,
    I'm having some troubles publishing my app. I'm using iBeacon inside an application for a resaturant. If the user approaches the restaurant the app should wake up due to a remote notification.
    To do this i need to allow "Location updates" in the Background Modes of the app and then in the .plist right?
    The problem is, Apple is rejecting the app because of unappropriated use of persistent background location service.
    How can I achieve the "waking up" of the app?

    Thanks for your help.

  • Avatar
    Wojtek Borowicz

    Hi Gabriele,

    It's not necessary to use location updates in the background modes and Apple frequently rejects apps that enable them but don't make actual use of them.

    Cheers.

  • Avatar
    Kepa Santos

    Hi!

    Apple is rejecting my app because of unappropriated use of persistent background location service.

    But if i want to be monitoring for the beacons in the background i dont need to check Location updates and ask for "requestAlwaysAuthorization" ?

    Thanks

  • Avatar
    Gabriele Ciaravolo

    Hi Kepa,
    I had the same issue. The problem isn't the "requestAlwaysAuthorization" but the Capabilities of your app. You shoudn't check "location updates" or the app will be rejected.
    However, without the "location updates" service u cannot Range Beacons, you can only monitor Reagions with didExitRegion and didEnterRegion.
    in this two methods you can send some push to wake up the app and then, after the app is opened you can Range Beacons and get their informations.
    Apple is relly strict about that.

  • Avatar
    Kepa Santos

    Hi Gabriele!

    Thanks for your help, so "location updates" isnt necessary for monitoring. In all tutorials and examples that i had readed marked as necessary. But I'm testing and it seems that in fact is not necessary.

  • Avatar
    Wojtek Borowicz

    Hi Kepa,

    As Gabriele already mentioned, Apple is really strict about ranging in the background. We have written about this in more detail right here: https://community.estimote.com/hc/en-us/articles/203914068-Is-it-possible-to-use-beacon-ranging-in-the-background-

    Cheers.

  • Avatar
    Tera Caijiawen

    HI, thank you for the tutorial.
    Currently, i try to build a beacon detection framework, so my beacon detection method is not in app delegate. I have one question is about when the app is killed the location icon is still there. Then i try to do some checking like if the bluetooth state change to off then i turn off the location service. But this work when the app is in foreground and background but when app is killed then this function is no longer work. Do you have any idea on how to do that if my sample app is killed, then i still can detect the status of bluetooth. For example,If bluetooth is on then the location service is automatic on.
    Thank you.

Estimote is
hiring!