react-native-permissions icon indicating copy to clipboard operation
react-native-permissions copied to clipboard

iOS: Allow requesting LOCATION_ALWAYS if LOCATION_WHEN_IN_USE is granted.

Open tallpants opened this issue 4 years ago • 15 comments

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 had LOCATION_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 requested LOCATION_ALWAYS in the past, we return NotDetermined.
    • If the current authorization status is AuthorizedWhenInUse and we have requested LOCATION_ALWAYS in the past, we return Denied, since we're not allowed to prompt for this permission twice.
  • For request:
    • If the current authorization status is AuthorizedWhenInUse and we have not requested LOCATION_ALWAYS in the past, we call requestAlwaysAuthorization and flag the permission as requested.
    • If the current authorization status is AuthorizedWhenInUse and we have requested LOCATION_ALWAYS in the past, then we return the current authorization result, since we're not allowed to prompt for this permission twice.

Test Plan

  • Request and grant LOCATION_WHEN_IN_USE permission.
  • Then request LOCATION_ALWAYS permission.
Before After
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 in CHANGELOG.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)

tallpants avatar Oct 08 '20 21:10 tallpants

Amazing! Thank you so much, working flawlessly!

Peeeep avatar Oct 09 '20 11:10 Peeeep

@Peeeep happy to help! Make sure you read the limitations in the README!

tallpants avatar Oct 09 '20 11:10 tallpants

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.

taylorkline avatar Nov 19 '20 22:11 taylorkline

Will this be merged any time soon? Could really use this method for my project this week as Location Always is a necessity.

todesignandconquer avatar Dec 14 '20 21:12 todesignandconquer

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.

jureczkyb avatar Apr 17 '21 00:04 jureczkyb

Any updates on this?

antonigiske avatar Jul 02 '21 08:07 antonigiske

@antonigiske looks like it needs to be updated to current, then the commentary above needs to be handled

mikehardy avatar Jul 02 '21 15:07 mikehardy

Any updates on this?

harleenarora avatar Aug 20 '21 10:08 harleenarora

I used https://github.com/ds300/patch-package with this PR. That worked.

antonigiske avatar Aug 20 '21 10:08 antonigiske

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

mikehardy avatar Aug 20 '21 14:08 mikehardy

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 avatar Aug 24 '21 17:08 zoontek

@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

tallpants avatar Dec 21 '21 15:12 tallpants

Hello, my company need this feature, any solution or update about that?

Thanks!

Marcuspo avatar Jun 15 '22 17:06 Marcuspo

Looks like someone needs to sponsor it or do the updates like @zoontek's comment indicates and propose that

mikehardy avatar Jun 15 '22 18:06 mikehardy

Hello @Marcuspo ! Take a look at https://github.com/zoontek/react-native-permissions/issues/684 Your company can join me by email for sponsorship 🙂

zoontek avatar Jun 15 '22 18:06 zoontek