-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Conversation
@@ -135,7 +149,9 @@ - (dispatch_queue_t)methodQueue | |||
|
|||
- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter | |||
{ | |||
[self requestAuthorization]; | |||
if (!_locationConfiguration.skipPermissionRequests) { |
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.
wondering if we can just check that permissions are already granted instead of a skip flag
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.
@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.
Libraries/Geolocation/Geolocation.js
Outdated
* | ||
*/ | ||
setRNConfiguration: function( | ||
geo_config: GeoConfiguration |
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.
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) |
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.
Why the RN in the name? Can this be just setConfiguration:
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.
@javache "This method includes RN in the name to minimize the chances that the web spec will introduce an API with the same name."
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.
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 |
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.
Remove this completely and instead check on the JS side if the method exists before calling it.
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". |
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.
aabaecc
to
e6a02af
Compare
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. |
@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@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? |
@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) { |
@ngandhy That looks like a bug. Good find! Do you want to send a PR? Adam Comella |
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 |
@ngandhy, thanks, I'm glad you've found our work to be valuable :) |
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
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 includesRN
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
isfalse
. Verified the permission requests are skipped whenskipPermissionRequests
istrue
. Also, my team is using this change in our app.Adam Comella
Microsoft Corp.