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

iOS: Geolocation: Allow skipping of permission prompts #15096

Closed

Conversation

rigdern
Copy link
Contributor

@rigdern rigdern commented Jul 19, 2017

This change enables developers to tell the Geolocation module to skip its permissions requests so the app can manage the permissions requests on its own. React Native Android's Geolocation module already requires apps to request permissions on their own.

Currently, the Geolocation module automatically makes permissions requests for you based on what you've specified in your property list file. However, the property list file doesn't always represent what permissions the app wants right now. For example, suppose an app sometimes wants location when "in use" and sometimes wants location "always" depending on what app features the user has engaged with. The Geolocation API will request the "always" location permission even if that's not what the app wants for the current scenario.

This change enables developers to tell the Geolocation module to skip permission requests so that the app can explicitly ask for the appropriate permissions. By default, Geolocation will still ask for permissions so this is not a breaking change.

This change adds a method to Geolocation that is not supported by the web spec for geolocation (setRNConfiguration). This method includes RN in the name to minimize the chances that the web spec will introduce an API with the same name.

Test plan (required)

Verified that Geolocation requests permissions by default and when skipPermissionRequests is false. Verified the permission requests are skipped when skipPermissionRequests is true. Also, my team is using this change in our app.

Adam Comella
Microsoft Corp.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Jul 19, 2017
@facebook facebook deleted a comment from pull-bot Jul 19, 2017
@@ -135,7 +149,9 @@ - (dispatch_queue_t)methodQueue

- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter
{
[self requestAuthorization];
if (!_locationConfiguration.skipPermissionRequests) {
Copy link
Contributor

@chirag04 chirag04 Aug 9, 2017

Choose a reason for hiding this comment

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

wondering if we can just check that permissions are already granted instead of a skip flag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chirag04 That's an interesting suggestion. A downside to that design is it'll open the door to a tricky to catch app bug. Suppose the app wants to request permissions on its own but fails to. With the current implementation, the app will see an exception due to not having the proper permissions. With your suggestion, RN will request permissions on behalf of the app making it difficult for the developer to realize there's a bug in their app.

*
*/
setRNConfiguration: function(
geo_config: GeoConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

Use camelCase. In this case, just name the argument config

@@ -160,6 +176,11 @@ - (void)timeout:(NSTimer *)timer

#pragma mark - Public API

RCT_EXPORT_METHOD(setRNConfiguration:(RCTLocationConfiguration)config)
Copy link
Member

Choose a reason for hiding this comment

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

Why the RN in the name? Can this be just setConfiguration:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javache "This method includes RN in the name to minimize the chances that the web spec will introduce an API with the same name."

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, missed that in your original description. I think it's a good idea to avoid potential conflicts with the web spec. We can name the native module however we want though, so let's call the native method setConfiguration and the API on geolocation setReactConfiguration?

@@ -104,6 +104,11 @@ private static LocationOptions fromReactMap(ReadableMap map) {
}
}

@ReactMethod
Copy link
Member

Choose a reason for hiding this comment

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

Remove this completely and instead check on the JS side if the method exists before calling it.

@hramos
Copy link
Contributor

hramos commented Aug 15, 2017

I've taken a look at the current status of this PR, and based on the comments left by other reviewers as well as the conflicts, I'm marking it as "needs-revision".

Adam Comella added 2 commits August 16, 2017 15:35
Currently, the Geolocation module automatically makes permissions requests for you based on what you've specified in your property list file. However, the property list file doesn't always represent what permissions the app wants right now. For example, suppose an app sometimes wants location when "in use" and sometimes wants location "always" depending on what app features the user has engaged with. The Geolocation API will always request the "always" location permission even if that's not what the app wants for the current scenario.

This change enables developers to tell the Geolocation module to skip permission requests so that the app can explicitly ask for the appropriate permissions. By default, Geolocation will still ask for permissions so this is not a breaking change.

This change adds a method to Geolocation that is not supported by the web spec for geolocation (`setRNConfiguration`) This API includes `RN` in the name to minimize the chances that the web spec will ever introduce an API with the same name.

**Test plan (required)**

Verified that Geolocation requests permissions by default and when `skipPermissionRequests` is `false`. Verified the permission requests are skipped when `skipPermissionRequests` is `true`. Also, my team is using this change in our app.

Adam Comella
Microsoft Corp.
@rigdern
Copy link
Contributor Author

rigdern commented Aug 16, 2017

@hramos thanks for the ping.

@javache thanks for reviewing this. I pushed an update which addresses your comments. As described in my other comment, I left the method setRNConfiguration with the RN prefix. I justified why I used the prefix but if you'd prefer, I can remove the prefix. Let me know.

@rigdern
Copy link
Contributor Author

rigdern commented Aug 27, 2017

PR #15067 also solves this problem. We should figure out which PR to take. See my comment (#15067 (comment)) for a comparison of these PRs.

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Aug 29, 2017
@facebook-github-bot
Copy link
Contributor

@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@rigdern rigdern deleted the rigdern/skip-location-prompts branch August 30, 2017 07:16
@ngandhy
Copy link
Contributor

ngandhy commented Jan 8, 2018

@rigdern - when I add the line "navigator.geolocation.setRNConfiguration({'skipPermissionRequests':true});" to my code the location times out every time.

The second I remove the line of code, everything works again. Any tips / advice?

@ngandhy
Copy link
Contributor

ngandhy commented Jan 8, 2018

@rigdern @javache @hramos - Found the issue. _locationManager is never being set if you skip the permission request using skipPermissionsRequest:true. This is because _locationManager is being set INSIDE the authorization method.

Adding the following inside beginLocationUpdatesWithDesiredAccuracy fixes the issue.

if (!_locationManager) {
_locationManager = [CLLocationManager new];
_locationManager.delegate = self;
}

@rigdern
Copy link
Contributor Author

rigdern commented Jan 8, 2018

@ngandhy That looks like a bug. Good find! Do you want to send a PR?

Adam Comella
Microsoft Corp.

@ngandhy
Copy link
Contributor

ngandhy commented Jan 8, 2018

kk, I'll give it a try :)

Also, I've seen your features, fixes, and all the other stuff you're doing for the community and just wanted to say THANKS! I'm sure you guys don't hear it as much as you should

@rigdern
Copy link
Contributor Author

rigdern commented Jan 13, 2018

Also, I've seen your features, fixes, and all the other stuff you're doing for the community and just wanted to say THANKS! I'm sure you guys don't hear it as much as you should

@ngandhy, thanks, I'm glad you've found our work to be valuable :)

facebook-github-bot pushed a commit that referenced this pull request Jan 13, 2018
Summary:
This fixes #17486

make sure locationManager is being set before continuing.

Used if !locationManager vs else on previous statement as we should NEVER enter this code without _locationManager set. Also the else version might experience issues if someone touches the auth code and doesn't check this case, so seems more "long term stable".

<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

This fixes #17486

1) Have a working geolocation demo
2) Add navigator.geolocation.setRNConfiguration({'skipPermissionRequests':true}); to your code. I added it to the constructor or componentWillMount for the app.
3) Observe that geolocation no longer works (times out)
4) Apply patch
5) Observe that geolocation works again

re #15096

<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->

[IOS] [BUGFIX] [GeoLocation] - Fix skipPermissionRequests by setting _locationManager
Closes #17487

Differential Revision: D6718389

Pulled By: hramos

fbshipit-source-id: 08c1c9306b4d87cc40acdaa1550bb6df8345db02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants