Skip to content

Commit

Permalink
fix: update core location publishers to be on the type rather than st…
Browse files Browse the repository at this point in the history
…atic
  • Loading branch information
gtokman committed May 6, 2021
1 parent 68e26e5 commit 99ee929
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions Sources/ExtensionKit/CoreLocation/CLLocationManager.swift
Expand Up @@ -15,15 +15,15 @@ public extension CLLocationManager {
var cancellables = Set<AnyCancellable>()
func requestPermission() {
CLLocationManager
.requestLocationAuthorization(with: manager, type: .whenInUse)
manager
.requestLocationAuthorization(type: .whenInUse)
.assign(to: \.status, on: self)
.store(in: &cancellables)
}
func getLocation() {
CLLocationManager
.receiveLocationUpdates(from: manager)
manager
.receiveLocationUpdates()
.compactMap(\.last)
.map(\.coordinate)
.sink { result in
Expand All @@ -37,32 +37,29 @@ public extension CLLocationManager {
}
}
```
**/
*/
/// Request locaton authorization and subscribe to `CLAuthorizationStatus` updates
/// - Parameters:
/// - manager: `CLLocationManager`
/// - type: `AuthorizationType`
/// - Returns: Publisher with `AuthorizationType`
static func requestLocationAuthorization(
with manager: CLLocationManager,
func requestLocationAuthorization(
type: AuthorizationType
) -> AnyPublisher<CLAuthorizationStatus, Never> {
AuthorizationPublisher(manager: manager, authorizationType: type)
AuthorizationPublisher(manager: self, authorizationType: type)
.eraseToAnyPublisher()
}

/// Request locaton **always** authorization `CLAuthorizationStatus` with **upgrade** prompt (experimental)
/// - Parameters:
/// - manager: `CLLocationManager`
/// - Returns: Publisher with `AuthorizationType`
static func requestLocationAlwaysAuthorization(
with manager: CLLocationManager
) -> AnyPublisher<CLAuthorizationStatus, Never> {
AuthorizationPublisher(manager: manager, authorizationType: .always)
func requestLocationAlwaysAuthorization() -> AnyPublisher<CLAuthorizationStatus, Never> {
AuthorizationPublisher(manager: self, authorizationType: .whenInUse)
.flatMap { status -> AnyPublisher<CLAuthorizationStatus, Never> in
if status == CLAuthorizationStatus.authorizedAlways {
return AuthorizationPublisher(
manager: manager,
manager: self,
authorizationType: .always
)
.eraseToAnyPublisher()
Expand All @@ -75,10 +72,8 @@ public extension CLLocationManager {
/// Receive location updates from the `CLLocationManager`
/// - Parameter manager: `CLLocationManager`
/// - Returns: Publisher with `[CLLocation]` or `Error`
static func receiveLocationUpdates(
from manager: CLLocationManager
) -> AnyPublisher<[CLLocation], Error> {
LocationPublisher(manager: manager)
func receiveLocationUpdates() -> AnyPublisher<[CLLocation], Error> {
LocationPublisher(manager: self)
.eraseToAnyPublisher()
}

Expand Down

0 comments on commit 99ee929

Please sign in to comment.