Getting Permission
Location (and optionally Bluetooth permission for the CoreBluetooth module) should be requested within your app onboarding process.
For library versions 1.1 and below, they should be granted before starting the library.
For library versions 1.2 and above, you can start the library without location permission, and the library will listen for changes in permissions.
Requesting location permission should be done in 2 steps in order to enable us to gather more data from people that only give "While in use" permission.
Ensure you have both location permission descriptors in the Info.plist
file as follows:
<key>NSLocationWhenInUseUsageDescription</key>
<string>YOUR DESCRIPTIVE TEXT HERE</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>YOUR DESCRIPTIVE TEXT HERE</string>
Requesting When In Use location permission should happen first:
class MyClass: NSObject {
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
}
Then based on the user’s selection, either ask for always location permission or do nothing.
For listening to the user’s selection, a delegate for the CLLocationManager must be implemented as follows:
class MyClass: NSObject {
let locationManager = CLLocationManager()
init() {
locationManager.delegate = self
}
}
Extension MyClass: CLLocationManagerDelegate {
// Callback used by devices with iOS 14.0+
@available(iOS 14.0, *)
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
switch manager.authorizationStatus {
case .notDetermined, .restricted, .denied, .authorizedAlways:
break
case .authorizedWhenInUse:
locationManager.requestAlwaysAuthorization()
@unknown default:
break
}
}
// Callback used by devices with iOS older than 14.0
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .notDetermined, .restricted, .denied, .authorizedAlways:
break
case .authorizedWhenInUse:
locationManager.requestAlwaysAuthorization()
@unknown default:
break
}
}
}
Background Bluetooth Permission
This is only required if you integrate the CoreBluetooth module to support Eddystone beacons. Ensure you have the following additional entries in Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>YOUR_DESCRIPTIVE_TEXT_HERE</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>DESCRIPTIVE_TEXT_NOT_SHOWN_TO_THE_USER</string>
Also, Location in Background Modes should be enabled from the project’s Capabilities section or by adding the following in the Info.plist file:
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
The Bluetooth permission request will be triggered when you start the library
Background App Refresh
In order to accurately maintain the library in the right state, depending on the device location, Background App Refresh can be used.
For activating this feature, in `AppDelegate`’s `application(_ application:, didFinishLaunchingWithOptions:)` call `CrowdConnected.shared.activateSDKBackgroundRefresh()`. Also, in `SceneDelegate`’s `sceneDidEnterBackground(_ scene:)` call `CrowdConnected.shared.scheduleRefresh()`.
Device Aliases
Many use cases for background location data require the location data to be paired with a user ID or push nofication ID. This can be achieved using device aliases. See the Setting a Device Alias guide.