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

Configurable authorization level (iOS) #26

Merged

Conversation

tyronet-sportsbet
Copy link
Contributor

@tyronet-sportsbet tyronet-sportsbet commented Apr 18, 2019

Overview

As per comments in the react native issue 20879 thread, some organizations just want "when in use" permissions. However, because react native (and this library!) reference the requestAlwaysAuthorization selector, Apple requires us to include the NSLocationAlwaysUsageDescription in our Info.plist. We're happy to provide this key in our Info.plist, but react-native-geolocation should NOT always assume that means we want that permission, with no way to override it!

There are workarounds in that thread that involve applying patches that rewrite react native code to not reference that symbol. This is not a workable long term solution, in our specific case we have additional closed-source third party dependencies and some of them may reference this requestAlwaysAuthorization selector as well.

A solution that solves for all cases is to have the ability for the application to override the authorization level requested from CoreLocation. This PR implements that. I have added an additional configuration option to the setRNConfiguration GeoConfiguration object: authorizationLevel, which when provided will allow you to override which location services authorization level your application requests from the user. Two possible values, always and whenInUse.

Test Plan

A unit test here would need to be in the Objective-C side and I couldn't find any so in the absence of that, I've manually tested it:

  • Without providing the authorizationLevel key -> maintains old behaviour: it does.
  • Setting authorizationLevel to whenInUse -> requests "when in use" permissions: it does.
  • Setting authorizationLevel to always -> requests "always" permissions: it does.

Fixes #25

@matt-oakes matt-oakes self-requested a review April 18, 2019 00:33
Copy link
Collaborator

@matt-oakes matt-oakes left a comment

Choose a reason for hiding this comment

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

👋 Thanks @tyronet-sportsbet! This implementation looks really good. I like that it solves the issue people are having in a nice backward compatible way.

I've added one suggestion for changes to the types, just in case someone wants to explicitly use the auto behaviour without getting type errors.

After those are in and the tests are passing, I will merge and release this 👍

js/index.js Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
@matt-oakes
Copy link
Collaborator

The CircleCI errors look to be the usual Android flakiness. They should pass when you push the changes 👍

@tyronet-sportsbet
Copy link
Contributor Author

Thanks for the very quick response @matt-oakes ! I've made the requested changes, and as you predicted, the checks have passed 😄

@matt-oakes matt-oakes merged commit a9939cc into michalchudziak:master Apr 18, 2019
@matt-oakes
Copy link
Collaborator

Thanks, this looks great! Merging and releasing now :shipit:

react-native-community-bot pushed a commit that referenced this pull request Apr 18, 2019
# [1.2.0](v1.1.0...v1.2.0) (2019-04-18)

### Features

* **iOS:** Configurable authorization level  on iOS ([#26](#26)) ([a9939cc](a9939cc))
@react-native-community-bot
Copy link
Collaborator

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Purpose String in Info.plist File for NSLocationAlwaysUsageDescription
3 participants