mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 08:26:23 +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>
|
</array>
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
<false/>
|
<false/>
|
||||||
|
<key>NSLocationWhenInUseUsageDescription</key>
|
||||||
|
<string></string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -23,11 +23,9 @@ var subscriptions = [];
|
|||||||
var updatesEnabled = false;
|
var updatesEnabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* /!\ ATTENTION /!\
|
* You need to include the `NSLocationWhenInUseUsageDescription` key
|
||||||
* You need to add NSLocationWhenInUseUsageDescription key
|
* in Info.plist to enable geolocation. Geolocation is enabled by default
|
||||||
* in Info.plist to enable geolocation, otherwise it's going
|
* when you create a project with `react-native init`.
|
||||||
* to *fail silently*!
|
|
||||||
* \!/ \!/
|
|
||||||
*
|
*
|
||||||
* Geolocation follows the MDN specification:
|
* Geolocation follows the MDN specification:
|
||||||
* https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
|
* https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
|
||||||
|
@ -155,6 +155,8 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
RCT_EXPORT_METHOD(startObserving:(NSDictionary *)optionsJSON)
|
RCT_EXPORT_METHOD(startObserving:(NSDictionary *)optionsJSON)
|
||||||
{
|
{
|
||||||
|
[self checkLocationConfig];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
// Select best options
|
// Select best options
|
||||||
@ -189,6 +191,8 @@ RCT_EXPORT_METHOD(getCurrentPosition:(NSDictionary *)optionsJSON
|
|||||||
withSuccessCallback:(RCTResponseSenderBlock)successBlock
|
withSuccessCallback:(RCTResponseSenderBlock)successBlock
|
||||||
errorCallback:(RCTResponseSenderBlock)errorBlock)
|
errorCallback:(RCTResponseSenderBlock)errorBlock)
|
||||||
{
|
{
|
||||||
|
[self checkLocationConfig];
|
||||||
|
|
||||||
if (!successBlock) {
|
if (!successBlock) {
|
||||||
RCTLogError(@"%@.getCurrentPosition called with nil success parameter.", [self class]);
|
RCTLogError(@"%@.getCurrentPosition called with nil success parameter.", [self class]);
|
||||||
return;
|
return;
|
||||||
@ -319,4 +323,11 @@ RCT_EXPORT_METHOD(getCurrentPosition:(NSDictionary *)optionsJSON
|
|||||||
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
|
_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
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user