Overview
Location permission handling has changed substantially on both Android and iOS since 2018. The training code requests ACCESS_FINE_LOCATION using the old permission model; this needs updating to handle precise vs. approximate location (Android 12+), the separate background location permission (Android 10+), and updated iOS location authorization flows.
Background
Android Changes
| API Level |
Change |
| Android 10 (API 29) |
ACCESS_BACKGROUND_LOCATION introduced as a separate permission |
| Android 12 (API 31) |
Users can choose Approximate (COARSE) vs Precise (FINE) location even when FINE is requested |
| Android 12 (API 31) |
Apps must request COARSE and FINE together to show the choice dialog |
| Android 13 (API 33) |
Background location requires showing a rationale before sending user to Settings |
The current code requests only ACCESS_FINE_LOCATION. On Android 12+ the user sees a dialog offering both Precise and Approximate options, but the code doesn't handle the case where Approximate is chosen — TLocationSensor will still receive coordinates but with reduced accuracy (~3 km radius).
iOS Changes
- iOS 14:
CLLocationManager added accuracyAuthorization (.fullAccuracy vs .reducedAccuracy). Apps should request full accuracy with a purpose key (NSLocationDefaultAccuracyReduced) only when needed.
- "Allow Once" authorization added in iOS 13 — the app must handle single-use location grants.
NSLocationUsageDescription (pre-iOS 8 key) should be removed; use NSLocationWhenInUseUsageDescription only.
- Background location (
NSLocationAlwaysUsageDescription) should be removed if the app only needs foreground location.
Current Code
In formMain.pas and sensor-related frames, TLocationSensor is enabled and OnLocationChanged fires. The permission is checked/requested via direct JNI (TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION) and System.Permissions. The code does not distinguish between precise and approximate accuracy.
Files Affected
lab-src/Lab04.../forms/formMain.pas
lab-src/Lab05.../frames/uNewEntryFrame.pas
lab-src/Lab*/frames/uEntryDetailsFrame.pas
lab-src/Lab*/AndroidManifest.template.xml
Info.plist (all labs, via IDE plist editor)
Steps to Address
- Update runtime permission request to include both
ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION (required pair on Android 12+ to show the precision choice dialog).
- In the
OnLocationChanged handler, check TLocationSensor.Accuracy and display a UI indicator or warning if only approximate location is available.
- Remove
ACCESS_BACKGROUND_LOCATION from the manifest — FieldLogger only needs foreground location.
- On iOS, remove
NSLocationAlwaysUsageDescription from Info.plist if present; keep only NSLocationWhenInUseUsageDescription.
- Handle the
CLAuthorizationStatus.authorizedWhenInUse vs .authorizedAlways distinction — FieldLogger should only request "When In Use."
- Handle the iOS
reducedAccuracy case gracefully (same as Android approximate location).
- Update lab instructions to explain the new dual-permission model and precision choice.
Test Plan
Overview
Location permission handling has changed substantially on both Android and iOS since 2018. The training code requests
ACCESS_FINE_LOCATIONusing the old permission model; this needs updating to handle precise vs. approximate location (Android 12+), the separate background location permission (Android 10+), and updated iOS location authorization flows.Background
Android Changes
ACCESS_BACKGROUND_LOCATIONintroduced as a separate permissionCOARSE) vs Precise (FINE) location even whenFINEis requestedCOARSEandFINEtogether to show the choice dialogThe current code requests only
ACCESS_FINE_LOCATION. On Android 12+ the user sees a dialog offering both Precise and Approximate options, but the code doesn't handle the case where Approximate is chosen —TLocationSensorwill still receive coordinates but with reduced accuracy (~3 km radius).iOS Changes
CLLocationManageraddedaccuracyAuthorization(.fullAccuracyvs.reducedAccuracy). Apps should request full accuracy with a purpose key (NSLocationDefaultAccuracyReduced) only when needed.NSLocationUsageDescription(pre-iOS 8 key) should be removed; useNSLocationWhenInUseUsageDescriptiononly.NSLocationAlwaysUsageDescription) should be removed if the app only needs foreground location.Current Code
In
formMain.pasand sensor-related frames,TLocationSensoris enabled andOnLocationChangedfires. The permission is checked/requested via direct JNI (TJManifest_permission.JavaClass.ACCESS_FINE_LOCATION) andSystem.Permissions. The code does not distinguish between precise and approximate accuracy.Files Affected
Steps to Address
ACCESS_COARSE_LOCATIONandACCESS_FINE_LOCATION(required pair on Android 12+ to show the precision choice dialog).OnLocationChangedhandler, checkTLocationSensor.Accuracyand display a UI indicator or warning if only approximate location is available.ACCESS_BACKGROUND_LOCATIONfrom the manifest — FieldLogger only needs foreground location.NSLocationAlwaysUsageDescriptionfromInfo.plistif present; keep onlyNSLocationWhenInUseUsageDescription.CLAuthorizationStatus.authorizedWhenInUsevs.authorizedAlwaysdistinction — FieldLogger should only request "When In Use."reducedAccuracycase gracefully (same as Android approximate location).Test Plan
ACCESS_BACKGROUND_LOCATIONis requested.NSLocationWhenInUseUsageDescriptiontext.TLocationSensorcorrectly stops updates when the entry capture screen is dismissed.