Skip to content

Commit

Permalink
Merge pull request #22 from AsyncSwift/development
Browse files Browse the repository at this point in the history
Check app clip
  • Loading branch information
gre4ixin authored Oct 29, 2022
2 parents 291e6ae + babf5d5 commit 0ecd496
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
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
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!])
}
}

0 comments on commit 0ecd496

Please sign in to comment.