Skip to content

Commit 0ecd496

Browse files
authored
Merge pull request #22 from AsyncSwift/development
Check app clip
2 parents 291e6ae + babf5d5 commit 0ecd496

File tree

6 files changed

+79
-3
lines changed

6 files changed

+79
-3
lines changed

AsyncLocationKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = 'AsyncLocationKit'
33
s.module_name = 'AsyncLocationKit'
4-
s.version = '1.5.3'
4+
s.version = '1.5.4'
55
s.summary = '📍async/await CoreLocation'
66
s.homepage = 'https://github.com/AsyncSwift/AsyncLocationKit'
77
s.license = 'MIT'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Wrapper for Apple `CoreLocation` framework with new Concurency Model. No more `d
1111
##### SPM
1212
```swift
1313
dependencies: [
14-
.package(url: "https://github.com/AsyncSwift/AsyncLocationKit.git", .upToNextMinor(from: "1.5.0"))
14+
.package(url: "https://github.com/AsyncSwift/AsyncLocationKit.git", .upToNextMinor(from: "1.5.4"))
1515
]
1616
```
1717

1818
#### Cocoapods
1919
```
20-
pod 'AsyncLocationKit', :git => 'https://github.com/AsyncSwift/AsyncLocationKit.git', :tag => '1.5.2'
20+
pod 'AsyncLocationKit', :git => 'https://github.com/AsyncSwift/AsyncLocationKit.git', :tag => '1.5.4'
2121
```
2222

2323

Sources/AsyncLocationKit/AsyncLocationManager.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public final class AsyncLocationManager {
4545
locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
4646
}
4747

48+
public init(locationManager: CLLocationManager, desiredAccuracy: LocationAccuracy) {
49+
self.locationManager = locationManager
50+
self.locationManager.delegate = locationDelegate
51+
self.locationManager.desiredAccuracy = desiredAccuracy.convertingAccuracy
52+
proxyDelegate = AsyncDelegateProxy()
53+
locationDelegate = LocationDelegate(delegateProxy: proxyDelegate)
54+
}
55+
4856
public convenience init(desiredAccuracy: LocationAccuracy) {
4957
self.init()
5058
self.desiredAccuracy = desiredAccuracy
@@ -62,6 +70,7 @@ public final class AsyncLocationManager {
6270
locationManager.desiredAccuracy = newAccuracy.convertingAccuracy
6371
}
6472

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

92+
#if !APPCLIP
93+
@available(*, deprecated, message: "Use new function requestPermission(with:)")
8394
public func requestAuthorizationAlways() async -> CLAuthorizationStatus {
8495
let authorizationPerformer = RequestAuthorizationPerformer()
8596
return await withTaskCancellationHandler {
@@ -96,6 +107,20 @@ public final class AsyncLocationManager {
96107
}
97108
}
98109
}
110+
#endif
111+
112+
public func requestPermission(with permissionType: LocationPermission) async -> CLAuthorizationStatus {
113+
switch permissionType {
114+
case .always:
115+
#if APPCLIP
116+
return await requestAuthorizationWhenInUse()
117+
#else
118+
return await requestAuthorizationAlways()
119+
#endif
120+
case .whenInUsage:
121+
return await requestAuthorizationWhenInUse()
122+
}
123+
}
99124

100125
public func startUpdatingLocation() async -> LocationStream {
101126
let monitoringPerformer = MonitoringUpdateLocationPerformer()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Pavel Grechikhin on 29.10.2022.
6+
//
7+
8+
import Foundation
9+
10+
public enum LocationPermission {
11+
case always
12+
case whenInUsage
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import XCTest
2+
import CoreLocation
23
@testable import AsyncLocationKit
34

45
final class AsyncLocationKitTests: XCTestCase {
6+
let locationManager = AsyncLocationManager(locationManager: MockLocationManager(), desiredAccuracy: .bestAccuracy)
7+
8+
func testRequestLocation() async {
9+
do {
10+
let location = try await locationManager.requestLocation()
11+
12+
switch location {
13+
case .didUpdateLocations(let locations):
14+
print(locations)
15+
XCTAssert(true)
16+
default:
17+
XCTAssert(false, "Something went wrong")
18+
}
19+
20+
} catch {
21+
XCTAssert(false, error.localizedDescription)
22+
}
23+
}
524
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Pavel Grechikhin on 29.10.2022.
6+
//
7+
8+
import Foundation
9+
import CoreLocation
10+
11+
class MockLocationManager: CLLocationManager {
12+
override var location: CLLocation? {
13+
return CLLocation(latitude: 100, longitude: 200)
14+
}
15+
16+
override func requestLocation() {
17+
delegate?.locationManager?(self, didUpdateLocations: [location!])
18+
}
19+
}

0 commit comments

Comments
 (0)