mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 11:05:21 +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 = {
|
||||
|
||||
/*
|
||||
* 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
|
||||
* options: timeout (ms), maximumAge (ms), enableHighAccuracy (bool)
|
||||
|
@ -135,27 +135,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
- (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy distanceFilter:(CLLocationDistance)distanceFilter
|
||||
{
|
||||
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];
|
||||
}
|
||||
[self requestAuthorization];
|
||||
|
||||
_locationManager.distanceFilter = distanceFilter;
|
||||
_locationManager.desiredAccuracy = desiredAccuracy;
|
||||
@ -180,6 +160,31 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#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)
|
||||
{
|
||||
checkLocationConfig();
|
||||
|
Loading…
x
Reference in New Issue
Block a user