Background related guidelines

Background related guidelines

Your app behavior should be adapted depending on the background permissions you asked for in the app plist, and on the ones granted by your users.

Refer to https://docs.nao-cloud.com/docs/mobile-sdk/ios-sdk/configure-your-xcode-project/ for more details on the “Foreground” and “Background” Modes.

Common settings (Foreground and background)

Your app needs to set NSLocationWhenInUseUsageDescription permission in order to have access on the user’s location information. Add the following lines into your plist file

<key>NSLocationWhenInUseUsageDescription</key>
<string>NAO SDK will have access to your location information when using the application</string>

Since iOS 11
For the apps using the iOS 11 SDK, you are now required to provide an NSLocationWhenInUseUsageDescription key in all cases.

Foreground usage only (“While Using” permission only required)

There is no additional settings is need for foreground use case only.

Recommended call flow:

Stop all the location services upon entering background.

Code sample, building on the example:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];

- (void)onEnterBackground {
    [self.mlocationHandle stop];
    // call stop on all the handles that you might have instanciated before (e.g. geofencing).
}

- (void)onEnterForeground {
    [self.mlocationHandle start];
}

 

Important:

If your application does not support the on site wake-up, and does not require background operation, add the following code to your application:

if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
return;
}

Background usage (“Always” permission required)

NAO Cloud configuration

Enable background in the API Key parameters (the configuration change applies to all sites associated to this API Key):

  • Developer section -> API Keys, click on “Advanced” and “Edit parameters”
  • Check the “Background enabled” checkbox and save

iOS configuration

Regardless of the iOS version, the apps using NAOSDK need to set the both permissions: NSLocationAlwaysUsageDescription and  UIBackgroundModes. By setting NSLocationAlwaysUsageDescription, you requires the user for permission to access to their location all the time.

iOS 10 and earlier versions

<key>NSLocationAlwaysUsageDescription</key>
<string>Your iOS 10 and lower background location usage description goes here.</string>
<key>UIBackgroundModes</key>
<array><string>location</string></array> 

Since iOS 11

iOS 11 changes system indicators and permission prompts related to background location. Allows NAOSDK to access user’s location even when it’s in the background. Three permission requests are required and have be added to the Information Property List dictionary contained within your application’s plist file.

  1. NSLocationWhenInUseUsageDescription – A string value describing to the user why the application needs access to the current location when running in the foreground.
  2. NSLocationAlwaysAndWhenInUseUsageDesciption – The string displayed when permission is requested for always authorization using the requestAlwaysAuthorization method.
  3. NSLocationAlwaysUsageDescription – A string describing to the user why the application needs always access to the current location.

 

<key>NSLocationWhenInUseUsageDescription</key>
<string>A string value describing to the user why the application needs access to the current location when running in the foreground.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDesciption</key>
<string>The string displayed when permission is requested for always authorization using the requestAlwaysAuthorization method.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>A string describing to the user why the application needs always access to the current location.</string>

If you only provide NSLocationAlwaysAndWhenInUseUsageDescription but not NSLocationWhenInUseUsageDescription, asking for “Always” access will not work.

 

The key NSLocationAlwaysUsageDescription is still needed for backwards compatibility, in case you need to make the app available to iOS 10 users. For iOS 11 devices, this key is not needed.

Example of privacy-sensitive data rejection email for an app accessing the constant user’s location:

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data

Since iOS 13

  1. The Always Allow option, which grants an app “background” location access, has been removed from the initial location permissions prompt. Always Allow permission isn’t there by default in the new permission dialog. However, the developers might still include the previous location access settings in their app plist file so the iOS could prompt the user for Always permission later. To grant the app the location access in background,  we advise the developers to prompt the user with a message dialog that explains why the app need this authorization and redirects him to location device settings

     

    Example with a message that explains the need for always permission to receive proximity alerts for some deals 

     

     

     

     

  2. The iOS 13 added also a new permission prompt “Bluetooth permission”.  It shows a specific permission prompt when an app attempts to access any Bluetooth services. Hence, you now need to provide a new key permission “NSBluetoothAlwaysUsageDescription” for Corebluetooth framework usage.
    <key> NSBluetoothAlwaysUsageDescription </key>
    <string>This app would like to access Bluetooth to use the remote control.</string>
    

     

Recommended call flow

Never stop the location services upon entering background, but switch to low power mode to save battery.

Code sample, building on the example:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];

called when your app enters the background

- (void)onEnterBackground {
    [self.mlocationHandle setPowerMode:DBTPOWERMODE_LOW];
}

when your app comes back into the foreground

- (void)onEnterForeground {
     [self.mlocationHandle setPowerMode:DBTPOWERMODE_HIGH];
}

    • Related Articles

    • BLE beaconing interoperability – Basic guidelines

      The NAO Suite is designed to be interoperable with 3rd party BLE beacons and tags. This page aims at providing a first layer of interoperability requirements to ease the compatibility assessment with beacons & tags vendors. Disclaimer: This list is a ...
    • 8. Storage Related Resources

      Consider a situation when you need to create a resource that references a file (e.g: an image). The file needs to be uploaded before resource creation and after requested to get the credentials allowing you to upload to the storage service. The steps ...
    • 8. Storage Related Resources

      Consider a situation when you need to create a resource that references a file (e.g: an image). The file needs to be uploaded before resource creation and after requested to get the credentials allowing you to upload to the storage service. The steps ...
    • Release 20.06 (NAO SDK 4.9)

      Release 20.06 NAO Cloud – July, 9th 2020 New Features Import Visioglobe places as geofences. Beacons guidelines conformity: a new heatmap is now available, highlighting the areas that do not meet the radio requirements for the location engine. It is ...
    • Release 4.3

      Release V4.3.6 Date: 16 february 2017 Build: V4.3.6-R17865 Fixed Issue Geofencing handle init behavior: when a NAOGeofencingHandle is first instantiated, it should notify geofencing listener of zones the user is currently in via call to ...