From 17dbf988845bb7815dbb6182218c8c28d027fb91 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Tue, 2 Apr 2019 15:27:50 -0700 Subject: [PATCH] Move iOS Geolocation code out from the repo Summary: @public This resolves the iOS side of #20879. Reviewed By: natestedman, cpojer Differential Revision: D14712066 fbshipit-source-id: 88dd0ff80d3467b314cacb9349029dadca4ddf19 --- .../RCTGeolocation.xcodeproj/project.pbxproj | 257 ----------- Libraries/Geolocation/RCTLocationObserver.h | 12 - Libraries/Geolocation/RCTLocationObserver.m | 403 ------------------ .../Geolocation/React-RCTGeolocation.podspec | 35 -- RNTester/Podfile | 1 - RNTester/Podfile.lock | 7 - RNTester/RNTester.xcodeproj/project.pbxproj | 32 -- React.podspec | 1 - template/ios/Podfile | 1 - 9 files changed, 749 deletions(-) delete mode 100644 Libraries/Geolocation/RCTGeolocation.xcodeproj/project.pbxproj delete mode 100644 Libraries/Geolocation/RCTLocationObserver.h delete mode 100644 Libraries/Geolocation/RCTLocationObserver.m delete mode 100644 Libraries/Geolocation/React-RCTGeolocation.podspec diff --git a/Libraries/Geolocation/RCTGeolocation.xcodeproj/project.pbxproj b/Libraries/Geolocation/RCTGeolocation.xcodeproj/project.pbxproj deleted file mode 100644 index c0754118087ab4..00000000000000 --- a/Libraries/Geolocation/RCTGeolocation.xcodeproj/project.pbxproj +++ /dev/null @@ -1,257 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 134814061AA4E45400B7C361 /* RCTLocationObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 134814051AA4E45400B7C361 /* RCTLocationObserver.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 134814041AA4E45400B7C361 /* RCTLocationObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTLocationObserver.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - 134814051AA4E45400B7C361 /* RCTLocationObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTLocationObserver.m; sourceTree = ""; }; - 134814201AA4EA6300B7C361 /* libRCTGeolocation.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTGeolocation.a; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXGroup section */ - 134814211AA4EA7D00B7C361 /* Products */ = { - isa = PBXGroup; - children = ( - 134814201AA4EA6300B7C361 /* libRCTGeolocation.a */, - ); - name = Products; - sourceTree = ""; - }; - 58B511D21A9E6C8500147676 = { - isa = PBXGroup; - children = ( - 134814041AA4E45400B7C361 /* RCTLocationObserver.h */, - 134814051AA4E45400B7C361 /* RCTLocationObserver.m */, - 134814211AA4EA7D00B7C361 /* Products */, - ); - indentWidth = 2; - sourceTree = ""; - tabWidth = 2; - usesTabs = 0; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 58B511DA1A9E6C8500147676 /* RCTGeolocation */ = { - isa = PBXNativeTarget; - buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTGeolocation" */; - buildPhases = ( - 58B511D71A9E6C8500147676 /* Sources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = RCTGeolocation; - productName = RCTDataManager; - productReference = 134814201AA4EA6300B7C361 /* libRCTGeolocation.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 58B511D31A9E6C8500147676 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0940; - ORGANIZATIONNAME = Facebook; - TargetAttributes = { - 58B511DA1A9E6C8500147676 = { - CreatedOnToolsVersion = 6.1.1; - }; - }; - }; - buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTGeolocation" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 58B511D21A9E6C8500147676; - productRefGroup = 58B511D21A9E6C8500147676; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 58B511DA1A9E6C8500147676 /* RCTGeolocation */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 58B511D71A9E6C8500147676 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 134814061AA4E45400B7C361 /* RCTLocationObserver.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 58B511ED1A9E6C8500147676 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; - GCC_WARN_SHADOW = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - WARNING_CFLAGS = ( - "-Werror", - "-Wall", - ); - }; - name = Debug; - }; - 58B511EE1A9E6C8500147676 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; - GCC_WARN_SHADOW = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - VALIDATE_PRODUCT = YES; - WARNING_CFLAGS = ( - "-Werror", - "-Wall", - ); - }; - name = Release; - }; - 58B511F01A9E6C8500147676 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_STATIC_ANALYZER_MODE = deep; - LIBRARY_SEARCH_PATHS = "$(inherited)"; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - RUN_CLANG_STATIC_ANALYZER = YES; - }; - name = Debug; - }; - 58B511F11A9E6C8500147676 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_STATIC_ANALYZER_MODE = deep; - LIBRARY_SEARCH_PATHS = "$(inherited)"; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTGeolocation" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 58B511ED1A9E6C8500147676 /* Debug */, - 58B511EE1A9E6C8500147676 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTGeolocation" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 58B511F01A9E6C8500147676 /* Debug */, - 58B511F11A9E6C8500147676 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 58B511D31A9E6C8500147676 /* Project object */; -} diff --git a/Libraries/Geolocation/RCTLocationObserver.h b/Libraries/Geolocation/RCTLocationObserver.h deleted file mode 100644 index f3f9e19b8f2902..00000000000000 --- a/Libraries/Geolocation/RCTLocationObserver.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -@interface RCTLocationObserver : RCTEventEmitter - -@end diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m deleted file mode 100644 index f3b2209a39afc9..00000000000000 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ /dev/null @@ -1,403 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "RCTLocationObserver.h" - -#import -#import -#import - -#import -#import -#import -#import -#import - -typedef NS_ENUM(NSInteger, RCTPositionErrorCode) { - RCTPositionErrorDenied = 1, - RCTPositionErrorUnavailable, - RCTPositionErrorTimeout, -}; - -#define RCT_DEFAULT_LOCATION_ACCURACY kCLLocationAccuracyHundredMeters - -typedef struct { - BOOL skipPermissionRequests; -} RCTLocationConfiguration; - -typedef struct { - double timeout; - double maximumAge; - double accuracy; - double distanceFilter; - BOOL useSignificantChanges; -} RCTLocationOptions; - -@implementation RCTConvert (RCTLocationOptions) - -+ (RCTLocationConfiguration)RCTLocationConfiguration:(id)json -{ - NSDictionary *options = [RCTConvert NSDictionary:json]; - - return (RCTLocationConfiguration) { - .skipPermissionRequests = [RCTConvert BOOL:options[@"skipPermissionRequests"]] - }; -} - -+ (RCTLocationOptions)RCTLocationOptions:(id)json -{ - NSDictionary *options = [RCTConvert NSDictionary:json]; - - double distanceFilter = options[@"distanceFilter"] == NULL ? RCT_DEFAULT_LOCATION_ACCURACY - : [RCTConvert double:options[@"distanceFilter"]] ?: kCLDistanceFilterNone; - - return (RCTLocationOptions){ - .timeout = [RCTConvert NSTimeInterval:options[@"timeout"]] ?: INFINITY, - .maximumAge = [RCTConvert NSTimeInterval:options[@"maximumAge"]] ?: INFINITY, - .accuracy = [RCTConvert BOOL:options[@"enableHighAccuracy"]] ? kCLLocationAccuracyBest : RCT_DEFAULT_LOCATION_ACCURACY, - .distanceFilter = distanceFilter, - .useSignificantChanges = [RCTConvert BOOL:options[@"useSignificantChanges"]] ?: NO, - }; -} - -@end - -static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg /* nil for default */) -{ - if (!msg) { - switch (code) { - case RCTPositionErrorDenied: - msg = @"User denied access to location services."; - break; - case RCTPositionErrorUnavailable: - msg = @"Unable to retrieve location."; - break; - case RCTPositionErrorTimeout: - msg = @"The location request timed out."; - break; - } - } - - return @{ - @"code": @(code), - @"message": msg, - @"PERMISSION_DENIED": @(RCTPositionErrorDenied), - @"POSITION_UNAVAILABLE": @(RCTPositionErrorUnavailable), - @"TIMEOUT": @(RCTPositionErrorTimeout) - }; -} - -@interface RCTLocationRequest : NSObject - -@property (nonatomic, copy) RCTResponseSenderBlock successBlock; -@property (nonatomic, copy) RCTResponseSenderBlock errorBlock; -@property (nonatomic, assign) RCTLocationOptions options; -@property (nonatomic, strong) NSTimer *timeoutTimer; - -@end - -@implementation RCTLocationRequest - -- (void)dealloc -{ - if (_timeoutTimer.valid) { - [_timeoutTimer invalidate]; - } -} - -@end - -@interface RCTLocationObserver () - -@end - -@implementation RCTLocationObserver -{ - CLLocationManager *_locationManager; - NSDictionary *_lastLocationEvent; - NSMutableArray *_pendingRequests; - BOOL _observingLocation; - BOOL _usingSignificantChanges; - RCTLocationConfiguration _locationConfiguration; - RCTLocationOptions _observerOptions; -} - -RCT_EXPORT_MODULE() - -#pragma mark - Lifecycle - -- (void)dealloc -{ - _usingSignificantChanges ? - [_locationManager stopMonitoringSignificantLocationChanges] : - [_locationManager stopUpdatingLocation]; - - _locationManager.delegate = nil; -} - -- (dispatch_queue_t)methodQueue -{ - return dispatch_get_main_queue(); -} - -- (NSArray *)supportedEvents -{ - return @[@"geolocationDidChange", @"geolocationError"]; -} - -#pragma mark - Private API - -- (void)_beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy - distanceFilter:(CLLocationDistance)distanceFilter - useSignificantChanges:(BOOL)useSignificantChanges -{ - if (!_locationConfiguration.skipPermissionRequests) { - [self requestAuthorization]; - } - - if (!_locationManager) { - _locationManager = [CLLocationManager new]; - _locationManager.delegate = self; - } - - _locationManager.distanceFilter = distanceFilter; - _locationManager.desiredAccuracy = desiredAccuracy; - _usingSignificantChanges = useSignificantChanges; - - // Start observing location - _usingSignificantChanges ? - [_locationManager startMonitoringSignificantLocationChanges] : - [_locationManager startUpdatingLocation]; -} - -- (void)_stopUpdatingIfIdle { - if (_pendingRequests.count == 0 && !_observingLocation) { - _usingSignificantChanges ? - [_locationManager stopMonitoringSignificantLocationChanges] : - [_locationManager stopUpdatingLocation]; - } -} - -#pragma mark - Static Helpers - -static BOOL locationEventValid(NSDictionary *event, RCTLocationOptions options) { - return [NSDate date].timeIntervalSince1970 - [RCTConvert NSTimeInterval:event[@"timestamp"]] < options.maximumAge && - [event[@"coords"][@"accuracy"] doubleValue] <= options.accuracy; -} - -static void checkLocationConfig() -{ -#if RCT_DEV - if (!([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] || - [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] || - [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"])) { - RCTLogError(@"Either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription or NSLocationAlwaysAndWhenInUseUsageDescription key must be present in Info.plist to use geolocation."); - } -#endif -} - -#pragma mark - Timeout handler - -- (void)timeout:(NSTimer *)timer -{ - RCTLocationRequest *request = timer.userInfo; - NSString *message = [NSString stringWithFormat: @"Unable to fetch location within %.1fs.", request.options.timeout]; - request.errorBlock(@[RCTPositionError(RCTPositionErrorTimeout, message)]); - [_pendingRequests removeObject:request]; - - // Stop updating if not observing and no pending requests - [self _stopUpdatingIfIdle]; -} - -#pragma mark - Public API - -RCT_EXPORT_METHOD(setConfiguration:(RCTLocationConfiguration)config) -{ - _locationConfiguration = config; -} - -RCT_EXPORT_METHOD(requestAuthorization) -{ - if (!_locationManager) { - _locationManager = [CLLocationManager new]; - _locationManager.delegate = self; - } - // 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]; - } - } - // Request location access permission - if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] && - [_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { - [_locationManager requestAlwaysAuthorization]; - } else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] && - [_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { - [_locationManager requestWhenInUseAuthorization]; - } -} - -RCT_EXPORT_METHOD(startObserving:(RCTLocationOptions)options) -{ - checkLocationConfig(); - - // Select best options - _observerOptions = options; - for (RCTLocationRequest *request in _pendingRequests) { - _observerOptions.accuracy = MIN(_observerOptions.accuracy, request.options.accuracy); - } - - [self _beginLocationUpdatesWithDesiredAccuracy:_observerOptions.accuracy - distanceFilter:_observerOptions.distanceFilter - useSignificantChanges:_observerOptions.useSignificantChanges]; - _observingLocation = YES; -} - -RCT_EXPORT_METHOD(stopObserving) -{ - // Stop observing - _observingLocation = NO; - - // Stop updating if no pending requests - [self _stopUpdatingIfIdle]; - -} - -RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options - withSuccessCallback:(RCTResponseSenderBlock)successBlock - errorCallback:(RCTResponseSenderBlock)errorBlock) -{ - checkLocationConfig(); - - if (!successBlock) { - RCTLogError(@"%@.getCurrentPosition called with nil success parameter.", [self class]); - return; - } - - if (![CLLocationManager locationServicesEnabled]) { - if (errorBlock) { - errorBlock(@[ - RCTPositionError(RCTPositionErrorUnavailable, @"Location services disabled.") - ]); - return; - } - } - - if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { - if (errorBlock) { - errorBlock(@[ - RCTPositionError(RCTPositionErrorDenied, nil) - ]); - return; - } - } - - // Check if previous recorded location exists and is good enough - if (_lastLocationEvent && locationEventValid(_lastLocationEvent, options)) { - - // Call success block with most recent known location - successBlock(@[_lastLocationEvent]); - return; - } - - // Create request - RCTLocationRequest *request = [RCTLocationRequest new]; - request.successBlock = successBlock; - request.errorBlock = errorBlock ?: ^(NSArray *args){}; - request.options = options; - request.timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:options.timeout - target:self - selector:@selector(timeout:) - userInfo:request - repeats:NO]; - if (!_pendingRequests) { - _pendingRequests = [NSMutableArray new]; - } - [_pendingRequests addObject:request]; - - // Configure location manager and begin updating location - CLLocationAccuracy accuracy = options.accuracy; - if (_locationManager) { - accuracy = MIN(_locationManager.desiredAccuracy, accuracy); - } - [self _beginLocationUpdatesWithDesiredAccuracy:accuracy - distanceFilter:options.distanceFilter - useSignificantChanges:options.useSignificantChanges]; -} - -#pragma mark - CLLocationManagerDelegate - -- (void)locationManager:(CLLocationManager *)manager - didUpdateLocations:(NSArray *)locations -{ - // Create event - CLLocation *location = locations.lastObject; - _lastLocationEvent = @{ - @"coords": @{ - @"latitude": @(location.coordinate.latitude), - @"longitude": @(location.coordinate.longitude), - @"altitude": @(location.altitude), - @"accuracy": @(location.horizontalAccuracy), - @"altitudeAccuracy": @(location.verticalAccuracy), - @"heading": @(location.course), - @"speed": @(location.speed), - }, - @"timestamp": @([location.timestamp timeIntervalSince1970] * 1000) // in ms - }; - - // Send event - if (_observingLocation) { - [self sendEventWithName:@"geolocationDidChange" body:_lastLocationEvent]; - } - - // Fire off queued callbacks that pass maximumAge and accuracy filters - for (RCTLocationRequest *request in [_pendingRequests copy]) { - if (locationEventValid(_lastLocationEvent, request.options)) { - request.successBlock(@[_lastLocationEvent]); - [request.timeoutTimer invalidate]; - [_pendingRequests removeObject:request]; - } - } - - // Stop updating if not observing and no pending requests - [self _stopUpdatingIfIdle]; -} - -- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error -{ - // Check error type - NSDictionary *jsError = nil; - switch (error.code) { - case kCLErrorDenied: - jsError = RCTPositionError(RCTPositionErrorDenied, nil); - break; - case kCLErrorNetwork: - jsError = RCTPositionError(RCTPositionErrorUnavailable, @"Unable to retrieve location due to a network failure"); - break; - case kCLErrorLocationUnknown: - default: - jsError = RCTPositionError(RCTPositionErrorUnavailable, nil); - break; - } - - // Send event - if (_observingLocation) { - [self sendEventWithName:@"geolocationError" body:jsError]; - } - - // Fire all queued error callbacks - for (RCTLocationRequest *request in _pendingRequests) { - request.errorBlock(@[jsError]); - [request.timeoutTimer invalidate]; - } - [_pendingRequests removeAllObjects]; - -} - -@end diff --git a/Libraries/Geolocation/React-RCTGeolocation.podspec b/Libraries/Geolocation/React-RCTGeolocation.podspec deleted file mode 100644 index ebf10933a48f07..00000000000000 --- a/Libraries/Geolocation/React-RCTGeolocation.podspec +++ /dev/null @@ -1,35 +0,0 @@ -# coding: utf-8 -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -require "json" - -package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json"))) -version = package['version'] - -source = { :git => 'https://github.com/facebook/react-native.git' } -if version == '1000.0.0' - # This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in. - source[:commit] = `git rev-parse HEAD`.strip -else - source[:tag] = "v#{version}" -end - -Pod::Spec.new do |s| - s.name = "React-RCTGeolocation" - s.version = version - s.summary = "A geolocation API for React Native." - s.homepage = "http://facebook.github.io/react-native/" - s.documentation_url = "https://facebook.github.io/react-native/docs/geolocation" - s.license = package["license"] - s.author = "Facebook, Inc. and its affiliates" - s.platforms = { :ios => "9.0", :tvos => "9.2" } - s.source = source - s.source_files = "*.{h,m}" - s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs" - s.header_dir = "React" - - s.dependency "React-Core", version -end diff --git a/RNTester/Podfile b/RNTester/Podfile index 229ecb58a21898..28157998bdc7e1 100644 --- a/RNTester/Podfile +++ b/RNTester/Podfile @@ -15,7 +15,6 @@ target 'RNTester' do pod 'React-RCTAnimation', :path => '../Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../Libraries/Blob' pod 'React-RCTCameraRoll', :path => '../Libraries/CameraRoll' - pod 'React-RCTGeolocation', :path => '../Libraries/Geolocation' pod 'React-RCTImage', :path => '../Libraries/Image' pod 'React-RCTLinking', :path => '../Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../Libraries/Network' diff --git a/RNTester/Podfile.lock b/RNTester/Podfile.lock index 85558e3680abe7..c6ef6ac2907c35 100644 --- a/RNTester/Podfile.lock +++ b/RNTester/Podfile.lock @@ -17,7 +17,6 @@ PODS: - React-RCTActionSheet (= 1000.0.0) - React-RCTAnimation (= 1000.0.0) - React-RCTBlob (= 1000.0.0) - - React-RCTGeolocation (= 1000.0.0) - React-RCTImage (= 1000.0.0) - React-RCTLinking (= 1000.0.0) - React-RCTNetwork (= 1000.0.0) @@ -71,8 +70,6 @@ PODS: - React-RCTCameraRoll (1000.0.0): - React-Core (= 1000.0.0) - React-RCTImage (= 1000.0.0) - - React-RCTGeolocation (1000.0.0): - - React-Core (= 1000.0.0) - React-RCTImage (1000.0.0): - React-Core (= 1000.0.0) - React-RCTNetwork (= 1000.0.0) @@ -110,7 +107,6 @@ DEPENDENCIES: - React-RCTAnimation (from `../Libraries/NativeAnimation`) - React-RCTBlob (from `../Libraries/Blob`) - React-RCTCameraRoll (from `../Libraries/CameraRoll`) - - React-RCTGeolocation (from `../Libraries/Geolocation`) - React-RCTImage (from `../Libraries/Image`) - React-RCTLinking (from `../Libraries/LinkingIOS`) - React-RCTNetwork (from `../Libraries/Network`) @@ -158,8 +154,6 @@ EXTERNAL SOURCES: :path: "../Libraries/Blob" React-RCTCameraRoll: :path: "../Libraries/CameraRoll" - React-RCTGeolocation: - :path: "../Libraries/Geolocation" React-RCTImage: :path: "../Libraries/Image" React-RCTLinking: @@ -197,7 +191,6 @@ SPEC CHECKSUMS: React-RCTAnimation: b324c6eb699637c735650c6180e13d003eeb0e56 React-RCTBlob: 069290c8db758bb1d77523a06d117dd668b6cef3 React-RCTCameraRoll: 353af870a0acd5ebb0bcf6a8187ed78d94c4c65e - React-RCTGeolocation: 4bbdba9893dc3f22b22553904e54ae46dcedf48b React-RCTImage: 012d845d919177e2726743ad06052dda66592760 React-RCTLinking: c6fe7b82bed97ce72203b2ce2f4aac87b1e2647f React-RCTNetwork: 2a2b22a17cd965de53ba21c5ca392d0da84ef322 diff --git a/RNTester/RNTester.xcodeproj/project.pbxproj b/RNTester/RNTester.xcodeproj/project.pbxproj index fb957fdccdf025..308e9bf4230a17 100644 --- a/RNTester/RNTester.xcodeproj/project.pbxproj +++ b/RNTester/RNTester.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FE81AA91428003F314A /* libRCTImage.a */; }; 134180011AA9153C003F314A /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FEF1AA914B8003F314A /* libRCTText.a */; }; 1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341802B1AA91779003F314A /* libRCTNetwork.a */; }; - 134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134A8A251AACED6A00945AAE /* libRCTGeolocation.a */; }; 134CB92A1C85A38800265FA6 /* RCTModuleInitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 134CB9291C85A38800265FA6 /* RCTModuleInitTests.m */; }; 138D6A181B53CD440074A87E /* RCTShadowViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 138D6A161B53CD440074A87E /* RCTShadowViewTests.m */; }; 138DEE241B9EDFB6007F4EA5 /* libRCTCameraRoll.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 138DEE091B9EDDDB007F4EA5 /* libRCTCameraRoll.a */; }; @@ -37,7 +36,6 @@ 1497CFB31B21F5E400C1F8F2 /* RCTUIManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */; }; 14D6D7111B220EB3001FB087 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14D6D7101B220EB3001FB087 /* libOCMock.a */; }; 14D6D71E1B2222EF001FB087 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147CED4B1AB34F8C00DA3E4C /* libRCTActionSheet.a */; }; - 14D6D7201B2222EF001FB087 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134A8A251AACED6A00945AAE /* libRCTGeolocation.a */; }; 14D6D7211B2222EF001FB087 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FE81AA91428003F314A /* libRCTImage.a */; }; 14D6D7221B2222EF001FB087 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341802B1AA91779003F314A /* libRCTNetwork.a */; }; 14D6D7231B2222EF001FB087 /* libRCTPushNotification.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14DC67F11AB71876001358AB /* libRCTPushNotification.a */; }; @@ -161,13 +159,6 @@ remoteGlobalIDString = 58B511DB1A9E6C8500147676; remoteInfo = RCTNetwork; }; - 134A8A241AACED6A00945AAE /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 134814201AA4EA6300B7C361; - remoteInfo = RCTGeolocation; - }; 138DEE081B9EDDDB007F4EA5 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 138DEE021B9EDDDB007F4EA5 /* RCTCameraRoll.xcodeproj */; @@ -492,7 +483,6 @@ 13417FE31AA91428003F314A /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../Libraries/Image/RCTImage.xcodeproj; sourceTree = ""; }; 13417FEA1AA914B8003F314A /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../Libraries/Text/RCTText.xcodeproj; sourceTree = ""; }; 134180261AA91779003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = ""; }; - 134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = ../Libraries/Geolocation/RCTGeolocation.xcodeproj; sourceTree = ""; }; 134CB9291C85A38800265FA6 /* RCTModuleInitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModuleInitTests.m; sourceTree = ""; }; 138D6A161B53CD440074A87E /* RCTShadowViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowViewTests.m; sourceTree = ""; }; 138DEE021B9EDDDB007F4EA5 /* RCTCameraRoll.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTCameraRoll.xcodeproj; path = ../Libraries/CameraRoll/RCTCameraRoll.xcodeproj; sourceTree = ""; }; @@ -586,7 +576,6 @@ 19BA89031F8439A700741C5A /* libRCTBlob.a in Frameworks */, 192F69DA1E8240E2008692C7 /* libRCTAnimation.a in Frameworks */, 14D6D71E1B2222EF001FB087 /* libRCTActionSheet.a in Frameworks */, - 14D6D7201B2222EF001FB087 /* libRCTGeolocation.a in Frameworks */, 14D6D7211B2222EF001FB087 /* libRCTImage.a in Frameworks */, 14D6D7221B2222EF001FB087 /* libRCTNetwork.a in Frameworks */, 14D6D7231B2222EF001FB087 /* libRCTPushNotification.a in Frameworks */, @@ -611,7 +600,6 @@ 147CED4C1AB3532B00DA3E4C /* libRCTActionSheet.a in Frameworks */, 13E501F11D07A84A005F35D8 /* libRCTAnimation.a in Frameworks */, 138DEE241B9EDFB6007F4EA5 /* libRCTCameraRoll.a in Frameworks */, - 134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */, 1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */, 13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */, 3578590A1B28D2CF00341EDB /* libRCTLinking.a in Frameworks */, @@ -696,7 +684,6 @@ 14E0EEC81AB118F7000DECC3 /* RCTActionSheet.xcodeproj */, 13E5019C1D07A502005F35D8 /* RCTAnimation.xcodeproj */, 138DEE021B9EDDDB007F4EA5 /* RCTCameraRoll.xcodeproj */, - 134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */, 13417FE31AA91428003F314A /* RCTImage.xcodeproj */, 357858F81B28D2C400341EDB /* RCTLinking.xcodeproj */, 134180261AA91779003F314A /* RCTNetwork.xcodeproj */, @@ -746,14 +733,6 @@ name = Products; sourceTree = ""; }; - 134A8A211AACED6A00945AAE /* Products */ = { - isa = PBXGroup; - children = ( - 134A8A251AACED6A00945AAE /* libRCTGeolocation.a */, - ); - name = Products; - sourceTree = ""; - }; 138DEE031B9EDDDB007F4EA5 /* Products */ = { isa = PBXGroup; children = ( @@ -1249,10 +1228,6 @@ ProductGroup = 138DEE031B9EDDDB007F4EA5 /* Products */; ProjectRef = 138DEE021B9EDDDB007F4EA5 /* RCTCameraRoll.xcodeproj */; }, - { - ProductGroup = 134A8A211AACED6A00945AAE /* Products */; - ProjectRef = 134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */; - }, { ProductGroup = 13417FE41AA91428003F314A /* Products */; ProjectRef = 13417FE31AA91428003F314A /* RCTImage.xcodeproj */; @@ -1329,13 +1304,6 @@ remoteRef = 1341802A1AA91779003F314A /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 134A8A251AACED6A00945AAE /* libRCTGeolocation.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libRCTGeolocation.a; - remoteRef = 134A8A241AACED6A00945AAE /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; 138DEE091B9EDDDB007F4EA5 /* libRCTCameraRoll.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/React.podspec b/React.podspec index 508283c0778c4e..935b00d2ffba5d 100644 --- a/React.podspec +++ b/React.podspec @@ -47,7 +47,6 @@ Pod::Spec.new do |s| s.dependency "React-RCTActionSheet", version s.dependency "React-RCTAnimation", version s.dependency "React-RCTBlob", version - s.dependency "React-RCTGeolocation", version s.dependency "React-RCTImage", version s.dependency "React-RCTLinking", version s.dependency "React-RCTNetwork", version diff --git a/template/ios/Podfile b/template/ios/Podfile index 9e03f39d025abe..5114274b54178e 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -9,7 +9,6 @@ target 'HelloWorld' do pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' - pod 'React-RCTGeolocation', :path => '../node_modules/react-native/Libraries/Geolocation' pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'