Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Fixed warnings #8

Merged
merged 3 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Example/LocationManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand All @@ -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 */ = {
Expand All @@ -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",
);
Expand All @@ -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 */
Expand Down
34 changes: 18 additions & 16 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
53 changes: 25 additions & 28 deletions Pod/Classes/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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 {
Expand Down Expand Up @@ -92,39 +92,41 @@ 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 {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend turning off whitespace-only lines in Xcode. It makes diffs much more cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkj-is Or I can add SwiftLint for this repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

if locationRequests.count > 0 || locationObservers.count > 0 {
if !locationRequests.isEmpty || !locationObservers.isEmpty {

askForLocationServicesIfNeeded()
_ = askForLocationServicesIfNeeded()
locationManager.startUpdatingLocation()
}

Expand All @@ -133,7 +135,7 @@ open class LocationManager: NSObject, CLLocationManagerDelegate {

@objc func stopUpdatingLocationIfPossible() {

if locationRequests.count == 0 && locationObservers.count == 0 {
if locationRequests.isEmpty && locationObservers.isEmpty {
locationManager.stopUpdatingLocation()
}

Expand All @@ -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
Expand Down Expand Up @@ -267,14 +269,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()
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/LocationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down