Skip to content

Commit 6623e48

Browse files
onchainguy-btcfacebook-github-bot-8
authored andcommitted
See issue #4886
Summary: brentvatne this is the pull request you requested See issue #4886 On iOS the plist key NSLocationAlwaysUsageDescription was ignored and the location could not be retreived when using this key. Now both keys NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription are supported. If NSLocationAlwaysUsageDescription is set, NSLocationWhenInUseUsageDescription will be simply ignored according to https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18 I read the contribution guidelines regarding the Objective-C coding standards. Hopefully my line length breaks are okay - otherwise just give me a shout and I will fix that. Didn't write any line of Objective-C before so^^ Closes #5093 Reviewed By: svcscm Differential Revision: D2823206 Pulled By: nicklockwood fb-gh-sync-id: dd856a18416796749025e4b32d9c72895401916d
1 parent 97dcc66 commit 6623e48

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Libraries/Geolocation/RCTLocationObserver.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ - (void)beginLocationUpdates
133133
}
134134

135135
// Request location access permission
136-
if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
136+
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] &&
137+
[_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
138+
[_locationManager requestAlwaysAuthorization];
139+
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] &&
140+
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
137141
[_locationManager requestWhenInUseAuthorization];
138142
}
139143

@@ -327,8 +331,9 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
327331

328332
- (void)checkLocationConfig
329333
{
330-
if (![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
331-
RCTLogError(@"NSLocationWhenInUseUsageDescription key must be present in Info.plist to use geolocation.");
334+
if (!([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] ||
335+
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"])) {
336+
RCTLogError(@"Either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription key must be present in Info.plist to use geolocation.");
332337
}
333338
}
334339

0 commit comments

Comments
 (0)