mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 05:34:15 +00:00
Ensure that NSLocationWhenInUseUsageDescription is set, throw error if not
Summary: As per #750, throw error when trying to use the geolocation module and this key is not set. cc @frantic Closes https://github.com/facebook/react-native/pull/762 Github Author: Brent Vatne <brent.vatne@madriska.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
parent
4a781dd8f2
commit
17ab4f2fb3
@ -36,5 +36,7 @@
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -23,11 +23,9 @@ var subscriptions = [];
|
||||
var updatesEnabled = false;
|
||||
|
||||
/**
|
||||
* /!\ ATTENTION /!\
|
||||
* You need to add NSLocationWhenInUseUsageDescription key
|
||||
* in Info.plist to enable geolocation, otherwise it's going
|
||||
* to *fail silently*!
|
||||
* \!/ \!/
|
||||
* You need to include the `NSLocationWhenInUseUsageDescription` key
|
||||
* in Info.plist to enable geolocation. Geolocation is enabled by default
|
||||
* when you create a project with `react-native init`.
|
||||
*
|
||||
* Geolocation follows the MDN specification:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
|
||||
|
@ -155,6 +155,8 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
RCT_EXPORT_METHOD(startObserving:(NSDictionary *)optionsJSON)
|
||||
{
|
||||
[self checkLocationConfig];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
// Select best options
|
||||
@ -189,6 +191,8 @@ RCT_EXPORT_METHOD(getCurrentPosition:(NSDictionary *)optionsJSON
|
||||
withSuccessCallback:(RCTResponseSenderBlock)successBlock
|
||||
errorCallback:(RCTResponseSenderBlock)errorBlock)
|
||||
{
|
||||
[self checkLocationConfig];
|
||||
|
||||
if (!successBlock) {
|
||||
RCTLogError(@"%@.getCurrentPosition called with nil success parameter.", [self class]);
|
||||
return;
|
||||
@ -319,4 +323,11 @@ RCT_EXPORT_METHOD(getCurrentPosition:(NSDictionary *)optionsJSON
|
||||
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
|
||||
}
|
||||
|
||||
- (void)checkLocationConfig
|
||||
{
|
||||
if (![[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
|
||||
RCTLogError(@"NSLocationWhenInUseUsageDescription key must be present in Info.plist to use geolocation.");
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user