mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 17:54:48 +00:00
Exposes requestAuthorization method.
Reviewed By: javache Differential Revision: D5129014 fbshipit-source-id: 1e0be6a8a00a2f38ca7b5b20d891148c5ba97467
This commit is contained in:
parent
7837bdbf7c
commit
3c64d95413
@ -71,6 +71,16 @@ type GeoOptions = {
|
|||||||
*/
|
*/
|
||||||
var Geolocation = {
|
var Geolocation = {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Request suitable Location permission based on the key configured on pList.
|
||||||
|
* If NSLocationAlwaysUsageDescription is set, it will request Always authorization,
|
||||||
|
* although if NSLocationWhenInUseUsageDescription is set, it will request InUse
|
||||||
|
* authorization.
|
||||||
|
*/
|
||||||
|
requestAuthorization: function() {
|
||||||
|
RCTLocationObserver.requestAuthorization();
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Invokes the success callback once with the latest location info. Supported
|
* Invokes the success callback once with the latest location info. Supported
|
||||||
* options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool)
|
* options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool)
|
||||||
|
@ -135,27 +135,7 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter
|
- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter
|
||||||
{
|
{
|
||||||
if (!_locationManager) {
|
[self requestAuthorization];
|
||||||
_locationManager = [CLLocationManager new];
|
|
||||||
_locationManager.delegate = self;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request location access permission
|
|
||||||
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] &&
|
|
||||||
[_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
|
|
||||||
[_locationManager requestAlwaysAuthorization];
|
|
||||||
|
|
||||||
// On iOS 9+ we also need to enable background updates
|
|
||||||
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
|
|
||||||
if(backgroundModes && [backgroundModes containsObject:@"location"]) {
|
|
||||||
if([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
|
|
||||||
[_locationManager setAllowsBackgroundLocationUpdates:YES];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] &&
|
|
||||||
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
|
|
||||||
[_locationManager requestWhenInUseAuthorization];
|
|
||||||
}
|
|
||||||
|
|
||||||
_locationManager.distanceFilter = distanceFilter;
|
_locationManager.distanceFilter = distanceFilter;
|
||||||
_locationManager.desiredAccuracy = desiredAccuracy;
|
_locationManager.desiredAccuracy = desiredAccuracy;
|
||||||
@ -180,6 +160,31 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
#pragma mark - Public API
|
#pragma mark - Public API
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(requestAuthorization)
|
||||||
|
{
|
||||||
|
if (!_locationManager) {
|
||||||
|
_locationManager = [CLLocationManager new];
|
||||||
|
_locationManager.delegate = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request location access permission
|
||||||
|
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] &&
|
||||||
|
[_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
|
||||||
|
[_locationManager requestAlwaysAuthorization];
|
||||||
|
|
||||||
|
// On iOS 9+ we also need to enable background updates
|
||||||
|
NSArray *backgroundModes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
|
||||||
|
if (backgroundModes && [backgroundModes containsObject:@"location"]) {
|
||||||
|
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
|
||||||
|
[_locationManager setAllowsBackgroundLocationUpdates:YES];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] &&
|
||||||
|
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
|
||||||
|
[_locationManager requestWhenInUseAuthorization];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(startObserving:(RCTLocationOptions)options)
|
RCT_EXPORT_METHOD(startObserving:(RCTLocationOptions)options)
|
||||||
{
|
{
|
||||||
checkLocationConfig();
|
checkLocationConfig();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user