From 70f61c2d8542cfc717328c13980deec389e72f0e Mon Sep 17 00:00:00 2001 From: RomanPodymov Date: Sun, 14 Oct 2018 14:58:29 +0200 Subject: [PATCH 1/3] replaced "open static" with "public static", using Array.isEmpty --- .../LocationManager.xcodeproj/project.pbxproj | 8 ++--- Example/Podfile.lock | 34 ++++++++++--------- Pod/Classes/LocationManager.swift | 12 +++---- Pod/Classes/LocationRequest.swift | 2 +- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Example/LocationManager.xcodeproj/project.pbxproj b/Example/LocationManager.xcodeproj/project.pbxproj index 23a8cd6..41acae8 100644 --- a/Example/LocationManager.xcodeproj/project.pbxproj +++ b/Example/LocationManager.xcodeproj/project.pbxproj @@ -293,7 +293,7 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-LocationManager_Example/Pods-LocationManager_Example-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-LocationManager_Example/Pods-LocationManager_Example-frameworks.sh", "${BUILT_PRODUCTS_DIR}/LocationManager/LocationManager.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", ); @@ -304,7 +304,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LocationManager_Example/Pods-LocationManager_Example-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LocationManager_Example/Pods-LocationManager_Example-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; AC28E080CCD6D0DE245F466D /* [CP] Check Pods Manifest.lock */ = { @@ -331,7 +331,7 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-LocationManager_Tests/Pods-LocationManager_Tests-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-LocationManager_Tests/Pods-LocationManager_Tests-frameworks.sh", "${BUILT_PRODUCTS_DIR}/LocationManager/LocationManager.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", ); @@ -342,7 +342,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LocationManager_Tests/Pods-LocationManager_Tests-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LocationManager_Tests/Pods-LocationManager_Tests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ diff --git a/Example/Podfile.lock b/Example/Podfile.lock index fba1695..236a1c6 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,30 +1,32 @@ PODS: - - LocationManager (2.0.0): - - PromiseKit (~> 4.0) - - PromiseKit (4.0.1): - - PromiseKit/Foundation (= 4.0.1) - - PromiseKit/QuartzCore (= 4.0.1) - - PromiseKit/UIKit (= 4.0.1) - - PromiseKit/CorePromise (4.0.1) - - PromiseKit/Foundation (4.0.1): + - LocationManager (2.0.1): + - PromiseKit (~> 6.0) + - PromiseKit (6.5.2): + - PromiseKit/CorePromise (= 6.5.2) + - PromiseKit/Foundation (= 6.5.2) + - PromiseKit/UIKit (= 6.5.2) + - PromiseKit/CorePromise (6.5.2) + - PromiseKit/Foundation (6.5.2): - PromiseKit/CorePromise - - PromiseKit/QuartzCore (4.0.1): - - PromiseKit/CorePromise - - PromiseKit/UIKit (4.0.1): + - PromiseKit/UIKit (6.5.2): - PromiseKit/CorePromise DEPENDENCIES: - LocationManager (from `../`) - - PromiseKit (~> 4.0) + - PromiseKit (~> 6.0) + +SPEC REPOS: + https://github.com/cocoapods/specs.git: + - PromiseKit EXTERNAL SOURCES: LocationManager: :path: "../" SPEC CHECKSUMS: - LocationManager: 614359c72d19c214be6a7445a5585771b6f9bf49 - PromiseKit: ae9e7f97ee758e23f7b9c5e80380a2e78d6338c5 + LocationManager: 50f673c57e4394fc19b49646254153fb96e52b9d + PromiseKit: 27c1601bfb73405871b805bcb8cf7e55c4dad3db -PODFILE CHECKSUM: 2278dbbe138896438a2d06a78afc6a2dccd11597 +PODFILE CHECKSUM: fb0e67fd662777f3e48be2660977a3207df4a2e1 -COCOAPODS: 1.0.1 +COCOAPODS: 1.6.0.beta.1 diff --git a/Pod/Classes/LocationManager.swift b/Pod/Classes/LocationManager.swift index 2827654..dedb396 100644 --- a/Pod/Classes/LocationManager.swift +++ b/Pod/Classes/LocationManager.swift @@ -23,8 +23,8 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { typealias AuthorizationFulfillment = (CLAuthorizationStatus) -> Void - @objc open static let locationDidChangeAuthorizationStatusNotification = "locationDidChangeAuthorizationStatusNotification" - @objc open static let sharedManager = LocationManager() + @objc public static let locationDidChangeAuthorizationStatusNotification = "locationDidChangeAuthorizationStatusNotification" + @objc public static let sharedManager = LocationManager() @objc var currentLocation: CLLocation? @objc internal var lastKnownLocation: CLLocation? @@ -34,7 +34,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { fileprivate var askForLocationServicesFulfillments = [AuthorizationFulfillment]() fileprivate let locationManager = CLLocationManager() - @objc open static var locationObserversCount: Int { + @objc public static var locationObserversCount: Int { return self.sharedManager.locationObserversCount } @objc open var locationObserversCount: Int { @@ -122,9 +122,9 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { @objc func startUpdatingLocationIfNeeded() { - if locationRequests.count > 0 || locationObservers.count > 0 { + if !locationRequests.isEmpty || !locationObservers.isEmpty { - askForLocationServicesIfNeeded() + _ = askForLocationServicesIfNeeded() locationManager.startUpdatingLocation() } @@ -133,7 +133,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { @objc func stopUpdatingLocationIfPossible() { - if locationRequests.count == 0 && locationObservers.count == 0 { + if locationRequests.isEmpty && locationObservers.isEmpty { locationManager.stopUpdatingLocation() } diff --git a/Pod/Classes/LocationRequest.swift b/Pod/Classes/LocationRequest.swift index 6088a45..e0103b0 100644 --- a/Pod/Classes/LocationRequest.swift +++ b/Pod/Classes/LocationRequest.swift @@ -64,7 +64,7 @@ class LocationRequest: NSObject { @objc func didTimeout() { - completeWith(location: locationManager.lastKnownLocation, force: true) + _ = completeWith(location: locationManager.lastKnownLocation, force: true) locationManager.locationRequestDidTimeout(self) } } From 0a77bbdae4f497a2a9402c6ffde7004ac030769b Mon Sep 17 00:00:00 2001 From: RomanPodymov Date: Sun, 14 Oct 2018 19:11:50 +0200 Subject: [PATCH 2/3] refactored for (_, request) in locationRequests.enumerated() --- Pod/Classes/LocationManager.swift | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/LocationManager.swift b/Pod/Classes/LocationManager.swift index dedb396..696713a 100644 --- a/Pod/Classes/LocationManager.swift +++ b/Pod/Classes/LocationManager.swift @@ -267,14 +267,9 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { if let lastLocation = locations.last { lastKnownLocation = lastLocation - - for (_, request) in locationRequests.enumerated() { - - if request.completeWith(location: lastLocation) { - remove(locationRequest: request) - } - } + locationRequests.filter { $0.completeWith(location: lastLocation) }.forEach(remove) + locationObservers.forEach { $0.update(location: lastLocation) } stopUpdatingLocationIfPossible() From d80da87404613e6d71f0ac7e66c32ef6aeb8038f Mon Sep 17 00:00:00 2001 From: RomanPodymov Date: Sun, 14 Oct 2018 20:56:07 +0200 Subject: [PATCH 3/3] refactored askWith() to avoid usage of var --- Pod/Classes/LocationManager.swift | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Pod/Classes/LocationManager.swift b/Pod/Classes/LocationManager.swift index 696713a..01ec491 100644 --- a/Pod/Classes/LocationManager.swift +++ b/Pod/Classes/LocationManager.swift @@ -92,32 +92,34 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { fileprivate func askWith(fulfillment: @escaping AuthorizationFulfillment, rejection: (Error) -> Void) -> Void { - var rejected = false - - if askForLocationServicesFulfillments.count == 0 { - + if !setupRequestPermissionsStrategy(rejection: rejection) { + askForLocationServicesFulfillments.append(fulfillment) + } + } + + private func setupRequestPermissionsStrategy(rejection: (Error) -> Void) -> Bool { + + if askForLocationServicesFulfillments.isEmpty { + if Bundle.main.object(forInfoDictionaryKey: "NSLocationAlwaysUsageDescription") != nil { - + if locationManager.responds(to: #selector(CLLocationManager.requestAlwaysAuthorization)) { locationManager.requestAlwaysAuthorization() } - + } else if Bundle.main.object(forInfoDictionaryKey: "NSLocationWhenInUseUsageDescription") != nil { - + if locationManager.responds(to: #selector(CLLocationManager.requestWhenInUseAuthorization)) { locationManager.requestWhenInUseAuthorization(); } - + } else { - + rejection(LocationManagerAuthorizationError.keyInPlistMissing) - rejected = true + return true } } - - if !rejected { - askForLocationServicesFulfillments.append(fulfillment) - } + return false } @objc func startUpdatingLocationIfNeeded() { @@ -156,7 +158,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate { locationManager.desiredAccuracy = desiredAccuracy } - if locationRequests.count == 0 { + if locationRequests.isEmpty { let observersDistanceFilter = locationObservers.map { (observer) -> CLLocationAccuracy in return observer.distanceFilter ?? 0