From b5a0401d2fdcfe63384ce680d851534a8e472daf Mon Sep 17 00:00:00 2001 From: Andrew Dodd <47298244+AndrewDodd42@users.noreply.github.com> Date: Mon, 21 Nov 2022 09:11:13 +0000 Subject: [PATCH 1/2] Fixed desiredAccuracy not being set when using convenience initialiser. Modified initialisers to use default parameters. --- .../AsyncLocationKit/AsyncLocationManager.swift | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Sources/AsyncLocationKit/AsyncLocationManager.swift b/Sources/AsyncLocationKit/AsyncLocationManager.swift index f9bc52b..69d432f 100644 --- a/Sources/AsyncLocationKit/AsyncLocationManager.swift +++ b/Sources/AsyncLocationKit/AsyncLocationManager.swift @@ -35,17 +35,12 @@ public final class AsyncLocationManager { private var locationManager: CLLocationManager private var proxyDelegate: AsyncDelegateProxyInterface private var locationDelegate: CLLocationManagerDelegate - private var desiredAccuracy: LocationAccuracy = .bestAccuracy - public init() { - locationManager = CLLocationManager() - proxyDelegate = AsyncDelegateProxy() - locationDelegate = LocationDelegate(delegateProxy: proxyDelegate) - locationManager.delegate = locationDelegate - locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy + public convenience init(desiredAccuracy: LocationAccuracy = .bestAccuracy) { + self.init(locationManager: CLLocationManager(), desiredAccuracy: desiredAccuracy) } - - public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy) { + + public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy = .bestAccuracy) { self.locationManager = locationManager proxyDelegate = AsyncDelegateProxy() locationDelegate = LocationDelegate(delegateProxy: proxyDelegate) @@ -53,10 +48,6 @@ public final class AsyncLocationManager { self.locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy } - public convenience init(desiredAccuracy: LocationAccuracy) { - self.init() - self.desiredAccuracy = desiredAccuracy - } public func getAuthorizationStatus() -> CLAuthorizationStatus { if #available(iOS 14, *) { From 31aca106419556ca0d2a9703ffeadec8c4ccad27 Mon Sep 17 00:00:00 2001 From: Andrew Dodd <47298244+AndrewDodd42@users.noreply.github.com> Date: Mon, 21 Nov 2022 09:11:46 +0000 Subject: [PATCH 2/2] Added test of desired accuracy setting. --- .../AsyncLocationKitTests.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift b/Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift index d9e3507..6048346 100644 --- a/Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift +++ b/Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift @@ -3,10 +3,21 @@ import CoreLocation @testable import AsyncLocationKit final class AsyncLocationKitTests: XCTestCase { - let locationManager = AsyncLocationManager(locationManager: MockLocationManager(), desiredAccuracy: .bestAccuracy) + static let mockLocationManager = MockLocationManager() + + func testDesiredAccuracy() { + let firstAccuracy: LocationAccuracy = .nearestTenMetersAccuracy + let locationManager = AsyncLocationManager(locationManager: AsyncLocationKitTests.mockLocationManager, desiredAccuracy: firstAccuracy) + XCTAssertTrue(AsyncLocationKitTests.mockLocationManager.desiredAccuracy == firstAccuracy.convertingAccuracy) + + let secondAccuracy: LocationAccuracy = .bestForNavigationAccuracy + locationManager.updateAccuracy(with: secondAccuracy) + XCTAssertTrue(AsyncLocationKitTests.mockLocationManager.desiredAccuracy == secondAccuracy.convertingAccuracy) + } func testRequestLocation() async { do { + let locationManager = AsyncLocationManager(locationManager: AsyncLocationKitTests.mockLocationManager) let location = try await locationManager.requestLocation() switch location {