Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1403 - On iOS, bypass 'always' permission by default #1404

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geolocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to the CHANGELOG.md file of the geolocator_apple package. Since the geolocator is setup according to the federated plugin architecture, each platform has it's own package that is published to pub.dev (although the platform specific packages are marked unlisted, they are still published). This means we have to keep track changes for each package in each of the CHANGELOG.md files.

Instead it would be nice if this could say something a long the lines of:

- 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

- Includes `altitudeAccuracy` and `headingAccuracy` in `Position`.
Expand Down
11 changes: 7 additions & 4 deletions geolocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ Starting from Android 10 you need to add the `ACCESS_BACKGROUND_LOCATION` permis
<details>
<summary>iOS</summary>

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
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
```

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 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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown in the README supports displaying formatted code by wrapping a certain section with backticks. In this case we can use it around the "'BYPASS_PERMISSION_LOCATION_ALWAYS=1'" keywords, which will render it as code. That means it will also not be necessary to inform developers to leave out the quotes (since the backticks are not rendered):

Suggested change
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.

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)

When using the `requestTemporaryFullAccuracy({purposeKey: "YourPurposeKey"})` method, a dictionary should be added to the Info.plist file.
```xml
Expand Down
2 changes: 1 addition & 1 deletion geolocator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions geolocator_apple/ios/Classes/Handlers/PermissionHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil) {
[locationManager requestWhenInUseAuthorization];
}
#if !BYPASS_PERMISSION_LOCATION_ALWAYS
else if ([self containsLocationAlwaysDescription]) {
[locationManager requestAlwaysAuthorization];
}
#endif
#endif
else {
if (self.errorHandler) {
Expand All @@ -89,6 +91,7 @@ - (void) requestPermission:(PermissionConfirmation)confirmationHandler
}
}

#if !BYPASS_PERMISSION_LOCATION_ALWAYS
- (BOOL) containsLocationAlwaysDescription {
BOOL containsAlwaysDescription = NO;
if (@available(iOS 11.0, *)) {
Expand All @@ -99,6 +102,7 @@ - (BOOL) containsLocationAlwaysDescription {
? containsAlwaysDescription
: [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil;
}
#endif

- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusNotDetermined) {
Expand Down
2 changes: 1 addition & 1 deletion geolocator_apple/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down