PushClient

public final class PushClient : @unchecked Sendable

Public-facing client that orchestrates Push MFA operations.

The client exposes high-level APIs for credential management, notification processing, and response handling while delegating business logic to the internal PushService. Clients should create instances using the DSL-style factory methods which encapsulate configuration defaults and dependency setup.

Factory Methods

  • Creates a PushClient using a DSL-style configuration closure.

    Throws

    PushError.initializationFailed when dependency setup fails.

    Declaration

    Swift

    public static func createClient(
        configure: (PushConfiguration) -> Void = { _ in }
    ) async throws -> PushClient

    Parameters

    configure

    Closure that mutates a fresh PushConfiguration.

    Return Value

    A fully initialized PushClient.

  • Creates a PushClient from an existing PushConfiguration instance.

    Throws

    PushError.initializationFailed when dependency setup fails.

    Declaration

    Swift

    public static func createClient(
        configuration: PushConfiguration
    ) async throws -> PushClient

    Parameters

    configuration

    Pre-constructed configuration object.

    Return Value

    A fully initialized PushClient.

Credential Operations

  • Registers a Push credential from a pushauth:// URI (typically obtained via QR code).

    Throws

    PushError when parsing, policy evaluation, registration, or storage fails.

    Declaration

    Swift

    public func addCredentialFromUri(_ uri: String) async throws -> PushCredential

    Parameters

    uri

    Enrollment URI containing credential details and registration parameters.

    Return Value

    The stored PushCredential instance.

  • saveCredential(_:) Asynchronous

    Persists a Push credential that was created or fetched externally.

    Throws

    PushError.storageFailure when persistence fails.

    Declaration

    Swift

    public func saveCredential(_ credential: PushCredential) async throws -> PushCredential

    Parameters

    credential

    The credential to store.

    Return Value

    The stored credential (potentially updated by policy evaluation).

  • getCredentials() Asynchronous

    Retrieves all stored Push credentials.

    Throws

    PushError.storageFailure when storage access fails.

    Declaration

    Swift

    public func getCredentials() async throws -> [PushCredential]

    Return Value

    Array of credentials currently known to the client.

  • Retrieves a single Push credential by identifier.

    Throws

    PushError.storageFailure when storage access fails.

    Declaration

    Swift

    public func getCredential(credentialId: String) async throws -> PushCredential?

    Parameters

    credentialId

    Identifier of the credential to fetch.

    Return Value

    The credential when found, otherwise nil.

  • Deletes a Push credential and any associated cached state.

    Throws

    PushError.storageFailure when storage access fails.

    Declaration

    Swift

    public func deleteCredential(credentialId: String) async throws -> Bool

    Parameters

    credentialId

    Identifier of the credential to remove.

    Return Value

    true when a credential was removed, false when it did not exist.

Device Token Management

  • Updates the APNs device token used for Push notifications.

    Throws

    PushError when validation, storage, or handler operations fail.

    Declaration

    Swift

    public func setDeviceToken(
        _ deviceToken: String,
        credentialId: String? = nil
    ) async throws -> Bool

    Parameters

    deviceToken

    Raw APNs device token string.

    credentialId

    Optional credential identifier to scope the update. When nil, all registered credentials are updated.

    Return Value

    true when the handler reports success for all updates (or the token is unchanged).

  • getDeviceToken() Asynchronous

    Retrieves the currently stored APNs device token, if available.

    Throws

    PushError.storageFailure when storage access fails.

    Declaration

    Swift

    public func getDeviceToken() async throws -> String?

    Return Value

    The device token string or nil when no token has been stored.

Notification Processing

  • Processes a push notification represented as a dictionary payload (e.g. APNs userInfo).

    Throws

    PushError when parsing or persistence fails.

    Declaration

    Swift

    public func processNotification(messageData: [String : Any]) async throws -> PushNotification?

    Parameters

    messageData

    Raw notification payload.

    Return Value

    The stored PushNotification (or nil when the payload is unsupported).

  • Processes a push notification represented as a string payload (typically JWT).

    Throws

    PushError when parsing or persistence fails.

    Declaration

    Swift

    public func processNotification(message: String) async throws -> PushNotification?

    Parameters

    message

    Encoded notification payload.

    Return Value

    The stored PushNotification (or nil when the payload is unsupported).

  • Processes a push notification using a UNNotification-style userInfo dictionary.

    This method automatically extracts APNs custom data from the nested aps dictionary format:

    • aps["data"]message (JWT)
    • aps["messageId"]messageId

    Throws

    PushError when parsing or persistence fails.

    Declaration

    Swift

    public func processNotification(userInfo: [AnyHashable : Any]) async throws -> PushNotification?

    Parameters

    userInfo

    Notification payload in [AnyHashable: Any] form (APNs userInfo).

    Return Value

    The stored PushNotification (or nil when unsupported).

Notification Responses

  • Approves a pending notification identified by notificationId.

    Throws

    PushError when the client is not initialized, the notification cannot be found, or handler/storage operations fail.

    Declaration

    Swift

    public func approveNotification(_ notificationId: String) async throws -> Bool

    Parameters

    notificationId

    Identifier of the notification to approve.

    Return Value

    true when the approval succeeds, false when the notification is no longer pending or the handler reports failure.

  • Approves a challenge-based notification by supplying the challenge response.

    Throws

    PushError.invalidParameterValue when the response is empty, or PushError surfaced by the underlying service.

    Declaration

    Swift

    public func approveChallengeNotification(
        _ notificationId: String,
        challengeResponse: String
    ) async throws -> Bool

    Parameters

    notificationId

    Identifier of the notification to approve.

    challengeResponse

    User-provided response required for number-matching flows.

    Return Value

    true when the approval succeeds.

  • Approves a biometric notification by indicating the authentication method used.

    Throws

    PushError.invalidParameterValue when the method is empty, or any PushError from the service.

    Declaration

    Swift

    public func approveBiometricNotification(
        _ notificationId: String,
        authenticationMethod: String
    ) async throws -> Bool

    Parameters

    notificationId

    Identifier of the notification to approve.

    authenticationMethod

    Method used to authenticate the user (for example, “face” or “fingerprint”).

    Return Value

    true when the approval succeeds.

  • denyNotification(_:) Asynchronous

    Denies a pending notification.

    Throws

    PushError surfaced from the underlying service operations.

    Declaration

    Swift

    public func denyNotification(_ notificationId: String) async throws -> Bool

    Parameters

    notificationId

    Identifier of the notification to deny.

    Return Value

    true when the denial succeeds.

Notification Queries & Cleanup

  • Retrieves all pending notifications awaiting user action.

    Throws

    PushError surfaced from storage operations.

    Declaration

    Swift

    public func getPendingNotifications() async throws -> [PushNotification]

    Return Value

    Array of pending notifications.

  • getAllNotifications() Asynchronous

    Retrieves all stored notifications, regardless of status.

    Throws

    PushError surfaced from storage operations.

    Declaration

    Swift

    public func getAllNotifications() async throws -> [PushNotification]

    Return Value

    Array of notifications.

  • Retrieves a specific notification by identifier.

    Throws

    PushError surfaced from storage operations.

    Declaration

    Swift

    public func getNotification(notificationId: String) async throws -> PushNotification?

    Parameters

    notificationId

    Identifier of the notification to fetch.

    Return Value

    The notification when found, otherwise nil.

  • Runs notification cleanup according to the configured strategy.

    Throws

    PushError when storage operations fail.

    Declaration

    Swift

    public func cleanupNotifications(credentialId: String? = nil) async throws -> Int

    Parameters

    credentialId

    Optional credential identifier to scope the cleanup.

    Return Value

    The number of notifications removed during cleanup.

  • close() Asynchronous

    Clears cached state and marks the client as uninitialized.

    Declaration

    Swift

    public func close() async