-
-
Notifications
You must be signed in to change notification settings - Fork 663
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
Issue #1403 - On iOS, bypass 'always' permission by default #1404
Conversation
…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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1404 +/- ##
===========================================
+ Coverage 94.73% 100.00% +5.26%
===========================================
Files 4 1 -3
Lines 114 30 -84
===========================================
- Hits 108 30 -78
+ Misses 6 0 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Apologies for the belated reply, and thank you very much for taking the time to submit this PR. I really like the idea of adding this option, however I was wondering if it is possible to flip the behaviour. The current implementation requires developers to explicitly turn the Would it be possible to reverse this behaviour and have developers that do not require background permissions explicitly turn it of? This would keep the default behaviour intact and prevents us from introducing a breaking change. Also could you update the |
This is an awesome change! I agree that breaking changes should be avoided, and I don't really care if I need to do some additional steps to avoid the "always" permission on iOS. I am a bit surprised that it currently isn't possible, and I'm even more surprised that this PR is discussed 1 day after I realised that I need this change to happen :) |
@mvanbeusekom happy to make that change, stay tuned |
…YS 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
@mvanbeusekom I have made the following changes:
I have to say I am a bit confused by the various versions of the example app in different directories, so had a hard time testing this time around. However, the latest change is minor (just added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @781flyingdutchman, they look good. I have two small points of feedback which would be great if you can have a look at.
geolocator/README.md
Outdated
``` | ||
|
||
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). |
There was a problem hiding this comment.
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):
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. |
geolocator/CHANGELOG.md
Outdated
## 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 |
There was a problem hiding this comment.
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`.
I thought I would try this PR out, so I pointed my pubspec.yaml to the fork that @781flyingdutchman have created like this:
After this I did a However I still get the warning-email from Apple. Have I done something wrong in the changes above? I also realised a problem with this solution, as soon as I run |
@mp-jojo Have you tried deleting the podspec.lock file and the POS directory, and then applying the preprocessor macro? This forces a rebuild and may solve the problem. If so, I will add that to the readme. I am not aware of a way to script this. In Swift you can change the Pod file but that doesn't work for C flags. If you know of a way, please let me know! |
I realised that the problem might have been that
I am however not sure if that solved it, or the fact that I deleted I also added the below script to the bottom of my
|
@mp-jojo, thank you for testing and glad it finally worked out. @781flyingdutchman, in the permission_handler plugin we also add preprocessor definitions to projects using the script mentioned by @mp-jojo (see iOS section of the readme). I think it might be nice to mention this as an alternative in the README of the |
Absolutely, that's how I've done it in background_downloader - I just didn't know how to do that for Objective C. |
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
Updated the README, CHANGELOG and Podfile as suggested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @781flyingdutchman for all your work and improvements
To prevent users getting rejected by Apple for not including NSLocationAlwaysAndWhenInUseUsageDescription even if they never require background location updates.
This PR makes the compilation of the code to request 'always' permission 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.
Changes:
I did not update the CHANGELOG as I imagine you may want to combine this with something else.
Pre-launch Checklist
pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or this PR is does not need version changes.CHANGELOG.md
to add a description of the change.///
).main
.dart format .
and committed any changes.flutter analyze
and fixed any errors.