From c933009fc4758ba2055fb7c0558f120ccdee5bc6 Mon Sep 17 00:00:00 2001 From: bram Date: Thu, 4 Jan 2024 18:10:50 -0800 Subject: [PATCH 1/3] 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) { From 4e5b972662d64c727b64ff911c585f816b620cb5 Mon Sep 17 00:00:00 2001 From: bram Date: Fri, 2 Feb 2024 20:52:27 -0800 Subject: [PATCH 2/3] Changed PERMISSION_LOCATION_ALWAYS to BYPASS_PERMISSION_LOCATION_ALWAYS such that the default behavior (no flag set) remains the same, and the change is non-breaking. Updated pubspec.yaml, README.md and CHANGELOG.md --- geolocator/CHANGELOG.md | 4 ++++ geolocator/README.md | 6 ++++-- geolocator/pubspec.yaml | 2 +- geolocator_apple/ios/Classes/Handlers/PermissionHandler.m | 4 ++-- geolocator_apple/pubspec.yaml | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/geolocator/CHANGELOG.md b/geolocator/CHANGELOG.md index 8ac1f3531..c2b2711d3 100644 --- a/geolocator/CHANGELOG.md +++ b/geolocator/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.1.1 + +- On iOS, adds option to bypass the request for permission to update location in the background (which can attract scrutiny from Apple upon app submission). To bypass, set the preprocessor macro BYPASS_PERMISSION_LOCATION_ALWAYS to 1 in XCode + ## 10.1.0 - Includes `altitudeAccuracy` and `headingAccuracy` in `Position`. diff --git a/geolocator/README.md b/geolocator/README.md index 99c234b44..28f5f3888 100644 --- a/geolocator/README.md +++ b/geolocator/README.md @@ -83,10 +83,12 @@ On iOS you'll need to add the following entry to your Info.plist file (located u This app needs access to location when open. ``` -If you would like to receive updates when your App is in the background, you'll also need to: +If you don't need to receive updates when your app is in the background, then add a compiler flag as follows: in XCode, click on Pods, choose the Target 'geolocator_apple', choose Build Settings, in the search box look for 'Preprocessor Macros' then add the 'BYPASS_PERMISSION_LOCATION_ALWAYS=1' flag (without the quotes). +Setting this flag prevents your app from requiring the `NSLocationAlwaysAndWhenInUseUsageDescription` entry in Info.plist, and avoids questions from Apple when submitting your app. + +If you do want to receive updates when your App is in the background (or if you don't bypass the permission request as described above) then you'll 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/pubspec.yaml b/geolocator/pubspec.yaml index 3494330da..8b5d6aa10 100644 --- a/geolocator/pubspec.yaml +++ b/geolocator/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator description: Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen -version: 10.1.0 +version: 10.1.1 environment: sdk: ">=2.15.0 <4.0.0" diff --git a/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m b/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m index 9b8fdf92a..42f4394ae 100644 --- a/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m +++ b/geolocator_apple/ios/Classes/Handlers/PermissionHandler.m @@ -72,7 +72,7 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil) { [locationManager requestWhenInUseAuthorization]; } -#if PERMISSION_LOCATION_ALWAYS +#if !BYPASS_PERMISSION_LOCATION_ALWAYS else if ([self containsLocationAlwaysDescription]) { [locationManager requestAlwaysAuthorization]; } @@ -91,7 +91,7 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler } } -#if PERMISSION_LOCATION_ALWAYS +#if !BYPASS_PERMISSION_LOCATION_ALWAYS - (BOOL) containsLocationAlwaysDescription { BOOL containsAlwaysDescription = NO; if (@available(iOS 11.0, *)) { diff --git a/geolocator_apple/pubspec.yaml b/geolocator_apple/pubspec.yaml index fa4224dd3..9f18896b9 100644 --- a/geolocator_apple/pubspec.yaml +++ b/geolocator_apple/pubspec.yaml @@ -2,7 +2,7 @@ name: geolocator_apple description: Geolocation Apple plugin for Flutter. This plugin provides the Apple implementation for the geolocator. repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_apple issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen -version: 2.3.5 +version: 2.3.6 environment: sdk: ">=2.15.0 <4.0.0" From 10923a381c6f668e1d1b293f29367b8bd15929e3 Mon Sep 17 00:00:00 2001 From: bram Date: Sun, 11 Feb 2024 12:46:53 -0800 Subject: [PATCH 3/3] Refinements to permission bypass for background location. Updates to CHANGELOG.md for geolocator and geolocator_apple Added code to Podfile for the examples in geolocator and geolocator_apple that - if uncommented - will bypass the permission request by automatically setting the bypass flag upon compilation. Updated README.md per suggestion --- geolocator/CHANGELOG.md | 2 +- geolocator/README.md | 15 ++++++++++++++- geolocator/example/ios/Podfile | 8 +++++++- geolocator_apple/CHANGELOG.md | 4 ++++ geolocator_apple/example/ios/Podfile | 6 ++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/geolocator/CHANGELOG.md b/geolocator/CHANGELOG.md index c2b2711d3..904f6ddfe 100644 --- a/geolocator/CHANGELOG.md +++ b/geolocator/CHANGELOG.md @@ -1,6 +1,6 @@ ## 10.1.1 -- On iOS, adds option to bypass the request for permission to update location in the background (which can attract scrutiny from Apple upon app submission). To bypass, set the preprocessor macro BYPASS_PERMISSION_LOCATION_ALWAYS to 1 in XCode +- Adds a description to the README on how to add the `BYPASS_PERMISSION_LOCATION_ALWAYS` preprocessor to bypass the need for adding the `NSLocationAlwaysUsageDescription` to the `Info.plist`. ## 10.1.0 diff --git a/geolocator/README.md b/geolocator/README.md index 28f5f3888..0389c8e9b 100644 --- a/geolocator/README.md +++ b/geolocator/README.md @@ -83,9 +83,22 @@ On iOS you'll need to add the following entry to your Info.plist file (located u This app needs access to location when open. ``` -If you don't need to receive updates when your app is in the background, then add a compiler flag as follows: in XCode, click on Pods, choose the Target 'geolocator_apple', choose Build Settings, in the search box look for 'Preprocessor Macros' then add the 'BYPASS_PERMISSION_LOCATION_ALWAYS=1' flag (without the quotes). +If you don't need to receive updates when your app is in the background, then add a compiler flag as follows: in XCode, click on Pods, choose the Target 'geolocator_apple', choose Build Settings, in the search box look for 'Preprocessor Macros' then add the `BYPASS_PERMISSION_LOCATION_ALWAYS=1` flag. Setting this flag prevents your app from requiring the `NSLocationAlwaysAndWhenInUseUsageDescription` entry in Info.plist, and avoids questions from Apple when submitting your app. +You can also have this flag be set automatically by adding to the `Podfile` for your application: +```agsl +post_install do |installer| + installer.pods_project.targets.each do |target| + if target.name == "geolocator_apple" + target.build_configurations.each do |config| + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1'] + end + end + end +end +``` + If you do want to receive updates when your App is in the background (or if you don't bypass the permission request as described above) then you'll 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) diff --git a/geolocator/example/ios/Podfile b/geolocator/example/ios/Podfile index f7d6a5e68..837295fed 100644 --- a/geolocator/example/ios/Podfile +++ b/geolocator/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' @@ -34,5 +34,11 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + # To bypass the permission check for background location updates, uncomment the following lines + #if target.name == "geolocator_apple" + # target.build_configurations.each do |config| + # config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1'] + # end + #end end end diff --git a/geolocator_apple/CHANGELOG.md b/geolocator_apple/CHANGELOG.md index bc5dd5b57..67c373776 100644 --- a/geolocator_apple/CHANGELOG.md +++ b/geolocator_apple/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.6 + +* Adds option to bypass the request for permission to update location in the background (which can attract scrutiny from Apple upon app submission). To bypass, set the preprocessor macro `BYPASS_PERMISSION_LOCATION_ALWAYS` to 1 in XCode + ## 2.3.5 * Previously the plugin filtered out negative values for heading and/or heading accuracy. Now the plugin is returning the heading and/or the heading accuracy even if the they have a negative value (invalid), so that the developer can use it and decide what to do with it. diff --git a/geolocator_apple/example/ios/Podfile b/geolocator_apple/example/ios/Podfile index e8a87fb96..87a77d50e 100644 --- a/geolocator_apple/example/ios/Podfile +++ b/geolocator_apple/example/ios/Podfile @@ -41,5 +41,11 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + # To bypass the permission check for background location updates, uncomment the following lines + #if target.name == "geolocator_apple" + # target.build_configurations.each do |config| + # config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1'] + # end + #end end end