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

[Geolocation] Add permissionTypeIOS option #1506

Closed
wants to merge 5 commits into from
Closed

[Geolocation] Add permissionTypeIOS option #1506

wants to merge 5 commits into from

Conversation

rt2zz
Copy link
Contributor

@rt2zz rt2zz commented Jun 3, 2015

This adds backgroundMode to the geolocation options. When options.backgroundMode === true for both gelocation.getCurrentPosition and gelocation.watchPosition:

  1. Enforce NSLocationAlwaysUsageDescription is set in Info.plist
  2. Requests requestAlwaysAuthorization as opposed to requestWhenInUseAuthorization

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jun 3, 2015
@ide
Copy link
Contributor

ide commented Jun 3, 2015

This should probably be an enum instead of a boolean or at least renamed to be clearer.

@rt2zz
Copy link
Contributor Author

rt2zz commented Jun 3, 2015

@ide something like permissionType: ENUM('IN_USE', 'ALWAYS') ?

Does using ios'y terms make sense or are we trying to keep things platform agnostic?

@ide
Copy link
Contributor

ide commented Jun 4, 2015

Android's permissioning is pretty different (coarse vs. fine updates rather than background vs. foreground) so I think we should optimize for iOS in this commit and clearly name the property something like permissionTypeIOS.

cc @frantic are you the right person to take a look at geolocation diffs (saw you were active on a few others)?

@frantic
Copy link
Contributor

frantic commented Jun 6, 2015

IIRC @sahrens built the original implementation. Re: this PR, I think we
should be explicit about the platform, especially when Android has a
different model
On Wed, Jun 3, 2015 at 5:19 PM James Ide notifications@github.com wrote:

Android's permissioning is pretty different (coarse vs. fine updates
rather than background vs. foreground) so I think we should optimize for
iOS in this commit and clearly name the property something like
permissionTypeIOS.

cc @frantic https://github.com/frantic are you the right person to take
a look at geolocation diffs (saw you were active on a few others)?


Reply to this email directly or view it on GitHub
#1506 (comment)
.

@rt2zz
Copy link
Contributor Author

rt2zz commented Jun 9, 2015

Ok, replaced backgroundMode with permissionTypeIOS which (if defined) must be one of ['ALWAYS', 'IN_USE']

I am not sure about the code style here, e.g. is it appropriate to use indexOf in an invariant argument as a surrogate for enum. Should we enum the permissionTypeIOS option again in objC land? Following react style is less obvious when working outside of components :(

Would it make sense to expose an explicity requestPermission method even though that does not conform for w3 geolocation spec?

@rt2zz rt2zz changed the title add backgroundMode to geolocation [Geolocation] Add permissionTypeIOS option Jun 10, 2015
{
[self checkLocationConfig];
NSLog(@"***$$$$$$$$$$$$$$$$$$$$$$$$ START OBS");
Copy link
Contributor

Choose a reason for hiding this comment

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

rm

@sahrens
Copy link
Contributor

sahrens commented Jun 13, 2015

This seems ok to - @nicklockwood, you re-wrote this recently, any qualms?

@sahrens sahrens self-assigned this Jun 13, 2015
@rt2zz
Copy link
Contributor Author

rt2zz commented Jun 13, 2015

Ah, thanks @sahrens

I changed the constants to be in line with react-native conventions, now: RCTPermissionTypeAlways, RCTPermissionTypeInUse, RCTPermissionKey. I also changed the permission type strings from all caps to camel case as that seems to be the convention, now: "always", "inUse"

@timdoes
Copy link

timdoes commented Jun 14, 2015

This is working great in the background. The only time it stops running is when the display is off. If I press the home button, it starts running again (even while locked) but as soon as the display goes black again, it stops running.

My code is the same as the React Native - Geolocation Example (with the added permissionTypeIOS: 'always').

Any ideas why this is happening? I will provide more details if needed.

Thanks! Love this!

@rt2zz
Copy link
Contributor Author

rt2zz commented Jun 14, 2015

@timdoes it may be an issue with your app setup. For example make sure the location background mode is enabled: https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/plist/info/UIBackgroundModes

This diff only changes the permission type requested, the mechanism for retrieving the location is still the standard startUpdatingLocation method https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/startUpdatingLocation

@timdoes
Copy link

timdoes commented Jun 14, 2015

My background mode declaration:

<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>location</string>
    <string>remote-notification</string>
</array>

Does this need to be used with a custom library class and bridged to React Native?

Sorry if this is a rookie question. Just thought this would add full background capabilities by just declaring the background mode and using the https://facebook.github.io/react-native/docs/geolocation.html example.

@rt2zz
Copy link
Contributor Author

rt2zz commented Jun 15, 2015

@timdoes just tested this out, and I see the same behaivor (no updates with display off). I do not have a definitive answer for you, apple does not make debugging this types of situations easy. You may consider playing around with allowDeferredLocationUpdatesUntilTraveled:timeout or signifigant location changes api or geofencing (none of which are currently supported by react-native gelocation)

@sahrens sahrens assigned nicklockwood and unassigned sahrens Jun 15, 2015
@sahrens
Copy link
Contributor

sahrens commented Jun 15, 2015

Actually going to pass this one to nick to finish review and import.

@machard
Copy link
Contributor

machard commented Sep 29, 2015

any news on what's causing the events not to fire when screen is locked ?
I see the same behavior with https://github.com/machard/react-native-location.

It must be in the way the bridge eventDispatcher works because didUpdateLocations is called.

@satya164
Copy link
Contributor

@nicklockwood @rt2zz Any updates on this?

@facebook-github-bot
Copy link
Contributor

@rt2zz updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@rt2zz updated the pull request.

@facebook-github-bot
Copy link
Contributor

@rt2zz updated the pull request.

@rt2zz
Copy link
Contributor Author

rt2zz commented Dec 23, 2015

@satya164 not sure about the status, but fwiw I just rebased against master, so if you want to take this patch for a test drive feel free.

@satya164
Copy link
Contributor

@rt2zz Everyone is on holiday. This PR might have to wait till next year :D

@facebook-github-bot
Copy link
Contributor

@rt2zz updated the pull request.

@brentvatne
Copy link
Collaborator

ping @nicklockwood :)

@nicklockwood
Copy link
Contributor

I'm not wholly happy with the implementation, but in the interests of moving forward, I'll accept this and then make some tweaks in a follow-up diff.

@nicklockwood
Copy link
Contributor

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1453225971642005/int_phab to review.

@rt2zz
Copy link
Contributor Author

rt2zz commented Jan 4, 2016

Thanks @nicklockwood - let me know if there is anything needed from me to follow up / tweak.

@nicklockwood
Copy link
Contributor

I'm closing this in favour of #5093, which solves the problem without exposing any proprietary props in Geolocation.js

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants