Skip to content
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
17 changes: 4 additions & 13 deletions Sources/AsyncLocationKit/AsyncLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,19 @@ 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)
self.locationManager.delegate = locationDelegate
self.locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
}

public convenience init(desiredAccuracy: LocationAccuracy) {
self.init()
self.desiredAccuracy = desiredAccuracy
}

public func getAuthorizationStatus() -> CLAuthorizationStatus {
if #available(iOS 14, *) {
Expand Down
13 changes: 12 additions & 1 deletion Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down