Skip to content

Commit 1adec8e

Browse files
Issue #1403 - On iOS, bypass 'always' permission by default (#1404)
* 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. * 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 * 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
1 parent ea54bac commit 1adec8e

File tree

8 files changed

+47
-7
lines changed

8 files changed

+47
-7
lines changed

geolocator/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 10.1.1
2+
3+
- 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`.
4+
15
## 10.1.0
26

37
- Includes `altitudeAccuracy` and `headingAccuracy` in `Position`.

geolocator/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,32 @@ Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permis
7676
<details>
7777
<summary>iOS</summary>
7878

79-
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):
79+
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):
8080

8181
``` xml
8282
<key>NSLocationWhenInUseUsageDescription</key>
8383
<string>This app needs access to location when open.</string>
84-
<key>NSLocationAlwaysUsageDescription</key>
85-
<string>This app needs access to location when in the background.</string>
8684
```
8785

88-
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.
86+
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.
87+
Setting this flag prevents your app from requiring the `NSLocationAlwaysAndWhenInUseUsageDescription` entry in Info.plist, and avoids questions from Apple when submitting your app.
88+
89+
You can also have this flag be set automatically by adding to the `Podfile` for your application:
90+
```agsl
91+
post_install do |installer|
92+
installer.pods_project.targets.each do |target|
93+
if target.name == "geolocator_apple"
94+
target.build_configurations.each do |config|
95+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1']
96+
end
97+
end
98+
end
99+
end
100+
```
101+
102+
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:
103+
* 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.
104+
* Add an `NSLocationAlwaysAndWhenInUseUsageDescription` entry to your Info.plist (use `NSLocationAlwaysUsageDescription` if you're targeting iOS <11.0)
89105

90106
When using the `requestTemporaryFullAccuracy({purposeKey: "YourPurposeKey"})` method, a dictionary should be added to the Info.plist file.
91107
```xml

geolocator/example/ios/Podfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
# platform :ios, '12.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
@@ -34,5 +34,11 @@ end
3434
post_install do |installer|
3535
installer.pods_project.targets.each do |target|
3636
flutter_additional_ios_build_settings(target)
37+
# To bypass the permission check for background location updates, uncomment the following lines
38+
#if target.name == "geolocator_apple"
39+
# target.build_configurations.each do |config|
40+
# config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1']
41+
# end
42+
#end
3743
end
3844
end

geolocator/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: geolocator
22
description: Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.
33
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator
44
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
5-
version: 10.1.0
5+
version: 10.1.1
66

77
environment:
88
sdk: ">=2.15.0 <4.0.0"

geolocator_apple/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.6
2+
3+
* 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
4+
15
## 2.3.5
26

37
* 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.

geolocator_apple/example/ios/Podfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ end
4141
post_install do |installer|
4242
installer.pods_project.targets.each do |target|
4343
flutter_additional_ios_build_settings(target)
44+
# To bypass the permission check for background location updates, uncomment the following lines
45+
#if target.name == "geolocator_apple"
46+
# target.build_configurations.each do |config|
47+
# config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'BYPASS_PERMISSION_LOCATION_ALWAYS=1']
48+
# end
49+
#end
4450
end
4551
end

geolocator_apple/ios/Classes/Handlers/PermissionHandler.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler
7272
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil) {
7373
[locationManager requestWhenInUseAuthorization];
7474
}
75+
#if !BYPASS_PERMISSION_LOCATION_ALWAYS
7576
else if ([self containsLocationAlwaysDescription]) {
7677
[locationManager requestAlwaysAuthorization];
7778
}
79+
#endif
7880
#endif
7981
else {
8082
if (self.errorHandler) {
@@ -89,6 +91,7 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler
8991
}
9092
}
9193

94+
#if !BYPASS_PERMISSION_LOCATION_ALWAYS
9295
- (BOOL) containsLocationAlwaysDescription {
9396
BOOL containsAlwaysDescription = NO;
9497
if (@available(iOS 11.0, *)) {
@@ -99,6 +102,7 @@ - (BOOL) containsLocationAlwaysDescription {
99102
? containsAlwaysDescription
100103
: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil;
101104
}
105+
#endif
102106

103107
- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
104108
if (status == kCLAuthorizationStatusNotDetermined) {

geolocator_apple/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: geolocator_apple
22
description: Geolocation Apple plugin for Flutter. This plugin provides the Apple implementation for the geolocator.
33
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_apple
44
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
5-
version: 2.3.5
5+
version: 2.3.6
66

77
environment:
88
sdk: ">=2.15.0 <4.0.0"

0 commit comments

Comments
 (0)