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
2 changes: 1 addition & 1 deletion AsyncLocationKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'AsyncLocationKit'
s.module_name = 'AsyncLocationKit'
s.version = '1.5.3'
s.version = '1.5.4'
s.summary = '📍async/await CoreLocation'
s.homepage = 'https://github.com/AsyncSwift/AsyncLocationKit'
s.license = 'MIT'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Wrapper for Apple `CoreLocation` framework with new Concurency Model. No more `d
##### SPM
```swift
dependencies: [
.package(url: "https://github.com/AsyncSwift/AsyncLocationKit.git", .upToNextMinor(from: "1.5.0"))
.package(url: "https://github.com/AsyncSwift/AsyncLocationKit.git", .upToNextMinor(from: "1.5.4"))
]
```

#### Cocoapods
```
pod 'AsyncLocationKit', :git => 'https://github.com/AsyncSwift/AsyncLocationKit.git', :tag => '1.5.2'
pod 'AsyncLocationKit', :git => 'https://github.com/AsyncSwift/AsyncLocationKit.git', :tag => '1.5.4'
```


Expand Down
25 changes: 25 additions & 0 deletions Sources/AsyncLocationKit/AsyncLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public final class AsyncLocationManager {
locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
}

public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy) {
self.locationManager = locationManager
self.locationManager.delegate = locationDelegate

Choose a reason for hiding this comment

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

I get the error "Variable 'self.locationDelegate' used before being initialized" on this line

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry for this, this init was created for tests, I did not notice an error when pushing, corrected :)

Choose a reason for hiding this comment

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

Thanks! Now it works just fine. And the solution to add the APPCLIP condition seems to work fine as well!

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice 😊

Choose a reason for hiding this comment

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

No, I celebrated to early. Uploading to TestFlight now gives the same error as before. I guess the APPCLIP flag does not propagate down to the SPM frameworks :( Not sure how to solve it now. I guess I either have to clone and copy down the code for this framework and the FLAG will be respected, or just skip the framework for my AppClip target and loose all GPS functionality for my AppClip-target :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you use cocoapods?

Choose a reason for hiding this comment

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

I've given up on Cocoapods a long time ago. SPM only now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll think about how to solve your problem)

self.locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
proxyDelegate = AsyncDelegateProxy()
locationDelegate = LocationDelegate(delegateProxy: proxyDelegate)
}

public convenience init(desiredAccuracy: LocationAccuracy) {
self.init()
self.desiredAccuracy = desiredAccuracy
Expand All @@ -62,6 +70,7 @@ public final class AsyncLocationManager {
locationManager.desiredAccuracy = newAccuracy.convertingAccuracy
}

@available(*, deprecated, message: "Use new function requestPermission(with:)")
public func requestAuthorizationWhenInUse() async -> CLAuthorizationStatus {
let authorizationPerformer = RequestAuthorizationPerformer()
return await withTaskCancellationHandler {
Expand All @@ -80,6 +89,8 @@ public final class AsyncLocationManager {
}
}

#if !APPCLIP
@available(*, deprecated, message: "Use new function requestPermission(with:)")
public func requestAuthorizationAlways() async -> CLAuthorizationStatus {
let authorizationPerformer = RequestAuthorizationPerformer()
return await withTaskCancellationHandler {
Expand All @@ -96,6 +107,20 @@ public final class AsyncLocationManager {
}
}
}
#endif

public func requestPermission(with permissionType: LocationPermission) async -> CLAuthorizationStatus {
switch permissionType {
case .always:
#if APPCLIP
return await requestAuthorizationWhenInUse()
#else
return await requestAuthorizationAlways()
#endif
case .whenInUsage:
return await requestAuthorizationWhenInUse()
}
}

public func startUpdatingLocation() async -> LocationStream {
let monitoringPerformer = MonitoringUpdateLocationPerformer()
Expand Down
13 changes: 13 additions & 0 deletions Sources/AsyncLocationKit/Settings/LocationPermission.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// File.swift
//
//
// Created by Pavel Grechikhin on 29.10.2022.
//

import Foundation

public enum LocationPermission {
case always
case whenInUsage
}
19 changes: 19 additions & 0 deletions Tests/AsyncLocationKitTests/AsyncLocationKitTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import XCTest
import CoreLocation
@testable import AsyncLocationKit

final class AsyncLocationKitTests: XCTestCase {
let locationManager = AsyncLocationManager(locationManager: MockLocationManager(), desiredAccuracy: .bestAccuracy)

func testRequestLocation() async {
do {
let location = try await locationManager.requestLocation()

switch location {
case .didUpdateLocations(let locations):
print(locations)
XCTAssert(true)
default:
XCTAssert(false, "Something went wrong")
}

} catch {
XCTAssert(false, error.localizedDescription)
}
}
}
19 changes: 19 additions & 0 deletions Tests/AsyncLocationKitTests/LocationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// File.swift
//
//
// Created by Pavel Grechikhin on 29.10.2022.
//

import Foundation
import CoreLocation

class MockLocationManager: CLLocationManager {
override var location: CLLocation? {
return CLLocation(latitude: 100, longitude: 200)
}

override func requestLocation() {
delegate?.locationManager?(self, didUpdateLocations: [location!])
}
}