react-native-permissions
react-native-permissions copied to clipboard
iOS: Allow requesting LOCATION_ALWAYS if LOCATION_WHEN_IN_USE is granted.
Summary
- Closes https://github.com/zoontek/react-native-permissions/issues/490
- Fixes an issue on iOS where you could not ask for
LOCATION_ALWAYS
permission if you already hadLOCATION_WHEN_IN_USE
permission. - This only impacts the
LocationAlways
pod. - Also updates the example project's Podfile to refer to the latest version of the repo (happens automatically when you
pod install
in the example project.)
Implementation changes
- For
check
:- If the current authorization status is
AuthorizedWhenInUse
, and we have not requestedLOCATION_ALWAYS
in the past, we returnNotDetermined
. - If the current authorization status is
AuthorizedWhenInUse
and we have requestedLOCATION_ALWAYS
in the past, we returnDenied
, since we're not allowed to prompt for this permission twice.
- If the current authorization status is
- For
request
:- If the current authorization status is
AuthorizedWhenInUse
and we have not requestedLOCATION_ALWAYS
in the past, we callrequestAlwaysAuthorization
and flag the permission as requested. - If the current authorization status is
AuthorizedWhenInUse
and we have requestedLOCATION_ALWAYS
in the past, then we return the current authorization result, since we're not allowed to prompt for this permission twice.
- If the current authorization status is
Test Plan
- Request and grant
LOCATION_WHEN_IN_USE
permission. - Then request
LOCATION_ALWAYS
permission.
Before | After |
---|---|
![]() |
![]() |
Compatibility
OS | Implemented |
---|---|
iOS | ✅ |
Android | N/A |
Checklist
- [X] I have tested this on a device and a simulator
- [X] I added the documentation in
README.md
- [ ] [Couldn't find a
CHANGELOG.md
] I mentioned this change inCHANGELOG.md
- [X] [No change] I updated the typed files (TS and Flow)
- [X] [No change] I added a sample use of the API in the example project (
example/App.js
)
Amazing! Thank you so much, working flawlessly!
@Peeeep happy to help! Make sure you read the limitations in the README!
I am using a patch and found a good workaround for finding out whether the user granted Always permissions or not.
Rather than awaiting the request
promise, as is obviously dangerous, I set up an AppState
listener. The AppState switches to inactive
when the user is interacting with the locations prompt, so I simply check the permission again when the AppState returns to active
.
Will this be merged any time soon? Could really use this method for my project this week as Location Always is a necessity.
Tested this change too and it looks pretty necessary. Without it on iOS 13+ we get blocked rather than upgrading the location when in use to always.
Any updates on this?
@antonigiske looks like it needs to be updated to current, then the commentary above needs to be handled
Any updates on this?
I used https://github.com/ds300/patch-package with this PR. That worked.
Hey folks, this is open source. In other words, not to be rude, but...get to work? Like, it needs your work to fix it. This PR has conflicts, how could a maintainer possibly merge it?
From a month ago
@antonigiske looks like it needs to be updated to current, then the commentary above needs to be handled
...and it looks like the magic work fairy hasn't shown up and done anything yet, so it's waiting on you!
Someone grab the code fix it up so it doesn't have conflicts and post a new PR.
Make sure to address the comments from the review: https://github.com/zoontek/react-native-permissions/pull/529#pullrequestreview-506583908
Until then, use patch-package I guess. But someone needs to do the work, that's the way work gets done
Like @mikehardy said, this is open source, everyone can contribute! But the points from the review need to be tackled indeed.
I'm currently don't use these permission handlers personally and have other projects / libraries, so it's not a priority for me to implement this.
But if your company needs this feature, I can take one day of my time to code it (without the never ending Promise, with tests on devices from iOS 10 to 15 and obviously a new release). For this, my freelance daily rate will apply. You can consider this as sponsoring if this library saved a lot of your time and money 🙂
@zoontek would you be okay merging this if I update the PR with @nasmuris's approach here to avoid having the unresolved promise? https://github.com/zoontek/react-native-permissions/pull/529#discussion_r550209147
Would really like to get this feature in after it's been up for so long
Hello, my company need this feature, any solution or update about that?
Thanks!
Looks like someone needs to sponsor it or do the updates like @zoontek's comment indicates and propose that
Hello @Marcuspo ! Take a look at https://github.com/zoontek/react-native-permissions/issues/684 Your company can join me by email for sponsorship 🙂