From c933009fc4758ba2055fb7c0558f120ccdee5bc6 Mon Sep 17 00:00:00 2001 From: bram Date: Thu, 4 Jan 2024 18:10:50 -0800 Subject: [PATCH] Issue #1403 - On iOS, add conditional compile of the request for 'always' permission, to prevent users getting rejected by Apple for not including NSLocationAlwaysAndWhenInUseUsageDescription even if they never require background location updates. The compile is conditional on the flag PERMISSION_LOCATION_ALWAYS being set in XCode under 'Preprocessor Macros'. If not set (the default) then the permission request for 'always' is not included in the binary, therefore not triggering a complaint by Apple. The request for 'always' (background) location updates is rare, so it is reasonable to have this turned off by default, and require some effort by the developer to activate this. --- geolocator/README.md | 9 +++++---- .../ios/Classes/Handlers/PermissionHandler.m | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/geolocator/README.md b/geolocator/README.md index 78e462618..99c234b44 100644 --- a/geolocator/README.md +++ b/geolocator/README.md @@ -76,16 +76,17 @@ Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permis
iOS -On iOS you'll need to add the following entries to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following (make sure you update the description so it is meaningfull in the context of your App): +On iOS you'll need to add the following entry to your Info.plist file (located under ios/Runner) in order to access the device's location. Simply open your Info.plist file and add the following (make sure you update the description so it is meaningfull in the context of your App): ``` xml NSLocationWhenInUseUsageDescription This app needs access to location when open. -NSLocationAlwaysUsageDescription -This app needs access to location when in the background. ``` -If you would like to receive updates when your App is in the background, you'll also need to add the Background Modes capability to your XCode project (Project > Signing and Capabilities > "+ Capability" button) and select Location Updates. Be careful with this, you will need to explain in detail to Apple why your App needs this when submitting your App to the AppStore. If Apple isn't satisfied with the explanation your App will be rejected. +If you would like to receive updates when your App is in the background, you'll also need to: +* Add the Background Modes capability to your XCode project (Project > Signing and Capabilities > "+ Capability" button) and select Location Updates. Be careful with this, you will need to explain in detail to Apple why your App needs this when submitting your App to the AppStore. If Apple isn't satisfied with the explanation your App will be rejected. +* Add an `NSLocationAlwaysAndWhenInUseUsageDescription` entry to your Info.plist (use `NSLocationAlwaysUsageDescription` if you're targeting iOS <11.0) +* Add a compiler flag: in XCode, click on Pods, choose the Target 'geolocator_apple', choose Build Settings, in the search box look for 'Preprocessor Macros' then add the 'PERMISSION_LOCATION_ALWAYS=1' flag (without the quotes) When using the `requestTemporaryFullAccuracy({purposeKey: "YourPurposeKey"})` method, a dictionary should be added to the Info.plist file. ```xml diff --git a/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m b/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m index 2b216e38d..9b8fdf92a 100644 --- a/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m +++ b/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m @@ -72,9 +72,11 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil) { [locationManager requestWhenInUseAuthorization]; } +#if PERMISSION_LOCATION_ALWAYS else if ([self containsLocationAlwaysDescription]) { [locationManager requestAlwaysAuthorization]; } +#endif #endif else { if (self.errorHandler) { @@ -89,6 +91,7 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler } } +#if PERMISSION_LOCATION_ALWAYS - (BOOL) containsLocationAlwaysDescription { BOOL containsAlwaysDescription = NO; if (@available(iOS 11.0, *)) { @@ -99,6 +102,7 @@ - (BOOL) containsLocationAlwaysDescription { ? containsAlwaysDescription : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil; } +#endif - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if (status == kCLAuthorizationStatusNotDetermined) {