Module responsible for monitoring the user’s geographic location. This module runs in the background and monitors the places visited by users.
To initialize the geolocation, the application needs the user’s permission, as shown in the steps below.
1. Add NSLocation keys into Application Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>The application $(EXECUTABLE_NAME) will use geolocation to optimize user experience.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>The application $(EXECUTABLE_NAME) will use geolocation to optimize user experience.</string>
<key>NSMotionUsageDescription</key>
<string>The $(EXECUTABLE_NAME) app will use your movements to optimize your experience.</string>
</dict>
</plist>
2. Enable access to WiFi information in Capabilities Access WiFi Information
:
3. Then turn on Location updates
in Capabilities:
4. In your AppDelegate, in the applicationDidBecomeActive
method, after starting the module, after permission to do Tracking, ask the user for permission for your application to use geolocation.
Task {
if await ATTrackingManager.requestTrackingAuthorization() == .authorized {
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
}
}
5. Implement the locationManagerDidChangeAuthorization
method of the CLLocationManagerDelegate delegate in your AppDelegate. Once the user permission is granted, validate the permission granted. If it is for App use only, request to always use it, otherwise, call the GeoBehavior module initialization:
switch manager.authorizationStatus {
case .authorizedWhenInUse:
manager.requestAlwaysAuthorization()
default:
break
}
MDMGeoBehavior.start()
Opt-out
To opt out of the module, just call the following command:
MDMGeoBehavior.setOptOut(true)
To unopt the module, just call the following command:
MDMGeoBehavior.setOptOut(false)