From 95d45d71a4e9c21bd97b02189d2d8342d41ea527 Mon Sep 17 00:00:00 2001 From: Tom Hutchinson Date: Tue, 22 Mar 2022 15:58:56 +0000 Subject: [PATCH] Return completion data when requesting temporary full accuracy permissions (#20) * Returns the completion closure's error or the updated accuracyAuthorization as a future * Callback with AccuracyAuthorization * Small tweaks * infer Co-authored-by: Stephen Celis --- Sources/ComposableCoreLocation/Interface.swift | 4 +--- Sources/ComposableCoreLocation/Live.swift | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Sources/ComposableCoreLocation/Interface.swift b/Sources/ComposableCoreLocation/Interface.swift index 8652870..0afb5af 100644 --- a/Sources/ComposableCoreLocation/Interface.swift +++ b/Sources/ComposableCoreLocation/Interface.swift @@ -294,9 +294,7 @@ public struct LocationManager { public var requestWhenInUseAuthorization: () -> Effect - public var requestTemporaryFullAccuracyAuthorization: - (String) - -> Effect + public var requestTemporaryFullAccuracyAuthorization: (String) -> Effect public var set: (Properties) -> Effect diff --git a/Sources/ComposableCoreLocation/Live.swift b/Sources/ComposableCoreLocation/Live.swift index f786e1a..5fbc8f4 100644 --- a/Sources/ComposableCoreLocation/Live.swift +++ b/Sources/ComposableCoreLocation/Live.swift @@ -103,13 +103,21 @@ extension LocationManager { } }, requestTemporaryFullAccuracyAuthorization: { purposeKey in - .fireAndForget { + .run { subscriber in #if (compiler(>=5.3) && !(os(macOS) || targetEnvironment(macCatalyst))) || compiler(>=5.3.1) if #available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, macCatalyst 14.0, *) { - manager - .requestTemporaryFullAccuracyAuthorization(withPurposeKey: purposeKey) + manager.requestTemporaryFullAccuracyAuthorization( + withPurposeKey: purposeKey + ) { error in + subscriber.send(completion: error.map { .failure(.init($0)) } ?? .finished) + } + } else { + subscriber.send(completion: .finished) } + #else + subscriber.send(completion: .finished) #endif + return AnyCancellable {} } }, set: { properties in