From 6623e482b2f14df1d379a124f876e297d49477e8 Mon Sep 17 00:00:00 2001 From: Sebastian Gronewold Date: Tue, 12 Jan 2016 03:11:00 -0800 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/5093 Reviewed By: svcscm Differential Revision: D2823206 Pulled By: nicklockwood fb-gh-sync-id: dd856a18416796749025e4b32d9c72895401916d --- Libraries/Geolocation/RCTLocationObserver.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m index 6ea912e45c1db4..63ceb7c9d95d64 100644 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ b/Libraries/Geolocation/RCTLocationObserver.m @@ -133,7 +133,11 @@ - (void)beginLocationUpdates } // Request location access permission - if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { + if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] && + [_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { + [_locationManager requestAlwaysAuthorization]; + } else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] && + [_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [_locationManager requestWhenInUseAuthorization]; } @@ -327,8 +331,9 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError * - (void)checkLocationConfig { - if (![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) { - RCTLogError(@"NSLocationWhenInUseUsageDescription key must be present in Info.plist to use geolocation."); + if (!([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] || + [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"])) { + RCTLogError(@"Either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription key must be present in Info.plist to use geolocation."); } }