From cbbe126d6486b451b03ed330a2557d12dc1d82c0 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Sat, 28 Sep 2024 20:27:30 +0200 Subject: [PATCH] Minor fixes --- ...zi+RegisterRemoteNotificationsAction.swift | 50 ++++++++++--------- .../Spezi+UnregisterRemoteNotifications.swift | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Sources/Spezi/Notifications/Spezi+RegisterRemoteNotificationsAction.swift b/Sources/Spezi/Notifications/Spezi+RegisterRemoteNotificationsAction.swift index 6db90b6..20883a9 100644 --- a/Sources/Spezi/Notifications/Spezi+RegisterRemoteNotificationsAction.swift +++ b/Sources/Spezi/Notifications/Spezi+RegisterRemoteNotificationsAction.swift @@ -10,28 +10,6 @@ import SpeziFoundation import SwiftUI -@MainActor -private final class RemoteNotificationContinuation: KnowledgeSource, Sendable { - typealias Anchor = SpeziAnchor - - fileprivate(set) var continuation: CheckedContinuation? - fileprivate(set) var access = AsyncSemaphore() - - - init() {} - - - @MainActor - func resume(with result: Result) { - if let continuation { - self.continuation = nil - access.signal() - continuation.resume(with: result) - } - } -} - - /// Registers to receive remote notifications through Apple Push Notification service. /// /// Refer to the documentation of ``Spezi/registerRemoteNotifications``. @@ -157,7 +135,7 @@ extension Spezi { extension Spezi.RegisterRemoteNotificationsAction { @MainActor static func handleDeviceTokenUpdate(_ spezi: Spezi, _ deviceToken: Data) { - guard let registration = spezi.storage[RemoteNotificationContinuation.self] else { + guard let registration = spezi.storage[Spezi.RemoteNotificationContinuation.self] else { return } @@ -169,7 +147,7 @@ extension Spezi.RegisterRemoteNotificationsAction { @MainActor static func handleFailedRegistration(_ spezi: Spezi, _ error: Error) { - guard let registration = spezi.storage[RemoteNotificationContinuation.self] else { + guard let registration = spezi.storage[Spezi.RemoteNotificationContinuation.self] else { return } @@ -180,3 +158,27 @@ extension Spezi.RegisterRemoteNotificationsAction { registration.resume(with: .failure(error)) } } + + +extension Spezi { + @MainActor + private final class RemoteNotificationContinuation: KnowledgeSource, Sendable { + typealias Anchor = SpeziAnchor + + fileprivate(set) var continuation: CheckedContinuation? + fileprivate(set) var access = AsyncSemaphore() + + + init() {} + + + @MainActor + func resume(with result: Result) { + if let continuation { + self.continuation = nil + access.signal() + continuation.resume(with: result) + } + } + } +} diff --git a/Sources/Spezi/Notifications/Spezi+UnregisterRemoteNotifications.swift b/Sources/Spezi/Notifications/Spezi+UnregisterRemoteNotifications.swift index 11af9ed..1af767a 100644 --- a/Sources/Spezi/Notifications/Spezi+UnregisterRemoteNotifications.swift +++ b/Sources/Spezi/Notifications/Spezi+UnregisterRemoteNotifications.swift @@ -14,7 +14,7 @@ import SwiftUI /// Refer to the documentation of ``Spezi/unregisterRemoteNotifications``. @_documentation(visibility: internal) @available(*, deprecated, renamed: "Spezi.UnregisterRemoteNotificationsAction", message: "Please use Spezi.UnregisterRemoteNotificationsAction") -public typealias UnregisterRemoteNotificationsAction = Spezi.RequestNotificationAuthorizationAction +public typealias UnregisterRemoteNotificationsAction = Spezi.UnregisterRemoteNotificationsAction extension Spezi {