iOS location permissions
Enable support for geofences and iBeacons
Location services will allow you to add geofence or iBeacon regions related to your app on the Xtremepush platform. This allows you to analyse your app audiences, visits to your locations and trigger notifications when they enter/exit/dwell at your locations.
Enable location services
In the standard Integration of the iOS SDK, Location Services are switched off.
They can be turned on using the setLocationEnabled
method.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ...
XPush.setLocationEnabled(true)
// ...
XPush.applicationDidFinishLaunching(options: launchOptions)
return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
[XPush setLocationEnabled:YES];
// ...
[XPush applicationDidFinishLaunchingWithOptions:launchOptions];
return YES;
}
You also need to add the following usage description keys and associated usage description text for location to your Info.plist
file. It will be shown to a user in the location permissions dialog.
NSLocationAlwaysUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription
Without these your app will not request location permission. You should explicitly state why your app needs the Always permission for whatever you use it for e.g. notifying you of special experiences at the stadium on game-day, adding reward points when you visit our store, etc.
iOS 13 periodic background usage reminder
From iOS 13 (September 2019), the operating system will periodically show a prompt to remind the user about apps using location in the background (ie. those which have been granted the Always permission). The user must confirm continued permission to access location.
The prompt includes a map showing where your app triggered geofences and where it checked location to make sure that nearby geofences were set correctly. Your location usage description is repeated here, so you should double-check the description accurately describes how you use location data, or you risk losing the user’s trust, and with it your background-location-access privileges.
iOS 13 changes to granting location permission
From iOS 13 (September 2019), apps requesting the Always permission will instead show an Allow Once option to the user for the app's first location prompt.
If the user chooses Allow Once, the app is granted location permission for a single foreground session only. When the user leaves the app or locks the device, the permission will automatically expire and the prompt will be shown again on the next use of location services.
If the user agrees to While Using App then in future, when your app would normally obtain a background location event (for example, an enter beacon region event), the user will be presented with an option to upgrade the permission to Always. If they do, your app will receive the background event.
Enable Bluetooth for iBeacons
Since version 4.1.0 of the Xtremepush SDK, you must explicitly enable support for iBeacons. This is to prevent your users being prompted (since iOS 13 in September 2019) to allow access to Bluetooth services unless you specifically need it.
To enable support for iBeacons and prompt your users to allow access to Bluetooth:
- Follow the steps above to enable Location Services
- Add the following method call immediately following the call to the
setLocationEnabled
:
XPush.setBeaconsEnabled(true)
[XPush setBeaconsEnabled:YES];
- Add the
NSBluetoothAlwaysUsageDescription
key and associated usage description to yourInfo.plist
file to explain the use of Bluetooth to your users.
In contrast to the existing
NSBluetoothPeripheralUsageDescription
required to Integrate the iOS SDK, this new description will be shown as part of the Bluetooth permission prompt, and also in the Settings app on the Bluetooth Privacy screens.
Updated over 4 years ago