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.
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>
There is no additional settings is need for foreground use case only.
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];
}
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;
}
Enable background in the API Key parameters (the configuration change applies to all sites associated to this API Key):
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.
<key>NSLocationAlwaysUsageDescription</key>
<string>Your iOS 10 and lower background location usage description goes here.</string>
<key>UIBackgroundModes</key>
<array><string>location</string></array>
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.
<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
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
<key> NSBluetoothAlwaysUsageDescription </key>
<string>This app would like to access Bluetooth to use the remote control.</string>
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];
}