Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 28, 2024
1 parent e55c7b5 commit cbbe126
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ import SpeziFoundation
import SwiftUI


@MainActor
private final class RemoteNotificationContinuation: KnowledgeSource, Sendable {
typealias Anchor = SpeziAnchor

fileprivate(set) var continuation: CheckedContinuation<Data, Error>?
fileprivate(set) var access = AsyncSemaphore()


init() {}


@MainActor
func resume(with result: Result<Data, Error>) {
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``.
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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<Data, Error>?
fileprivate(set) var access = AsyncSemaphore()


init() {}


@MainActor
func resume(with result: Result<Data, Error>) {
if let continuation {
self.continuation = nil
access.signal()
continuation.resume(with: result)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cbbe126

Please sign in to comment.