What's New / Privacy, Security & Identity

What's new in _AuthenticationServices_SwiftUI

+3 NewiOS · macOS

_AuthenticationServices_SwiftUI is a Swift cross-import overlay, not a standalone framework. Its API becomes available only when a target imports both AuthenticationServices and SwiftUI. It exposes AuthenticationServices types to SwiftUI's view and environment layer.

The 27 SDK adds 3 APIs, with no deprecations or removals. The new struct DeliveredVerificationCodesManager is exposed to views through EnvironmentValues.deliveredVerificationCodesManager, so SwiftUI code can read it from the environment.

New

3
struct

DeliveredVerificationCodesManager

NewiOSmacOS
public struct DeliveredVerificationCodesManager
Declaration
@MainActor public struct DeliveredVerificationCodesManager {

    public typealias VerificationError = ASDeliveredVerificationCodesManager.VerificationError

    /// Stream one-time codes received by the system.
    ///
    /// When requested, the user may decide whether your app may receive one-time codes.
    /// This stream will automatically disconnect after a period of time.
    ///
    /// - Parameters:
    ///     - preferredDuration: How long the stream should ideally remain connected. This duration is not guaranteed and defaults to 10 minutes.
    /// - Throws: `DeliveredVerificationCodesManager.VerificationError` if one-time codes can not be delivered.
    /// - Note: Only enabled credential providers may call this method.
    @MainActor public func oneTimeCodes(preferredDuration: TimeInterval = 600) async throws -> some AsyncSequence<ASVerificationCode, any Error>


    /// Mark a one-time code as "consumed" by the current process.
    ///
    /// A code should only be marked as consumed if it was submitted to a service for the purposes of authentication.
    ///
    /// Consuming a code will mark a code's containing message as read in the Messages and Mail apps.
    /// Depending on the user's preference, this may also delete the code's containing message.
    ///
    /// - Parameters:
    ///     - oneTimeCode: The code to mark as consumed.
    /// - Throws: `DeliveredVerificationCodesManager.VerificationError` if the system failed to accept the update.
    /// - Note: Only consume codes that you submit to a service. You should make a best effort to ensure it is accepted before calling this.
    @MainActor public func consumeOneTimeCode(_ oneTimeCode: ASVerificationCode) async throws
}
extension

DeliveredVerificationCodesManager

NewiOSmacOS
extension DeliveredVerificationCodesManager : Sendable
Declaration
extension DeliveredVerificationCodesManager : Sendable {
}
var

EnvironmentValues.deliveredVerificationCodesManager

NewiOSmacOS
public var deliveredVerificationCodesManager: DeliveredVerificationCodesManager { get }

This environment variable is for SwiftUI clients of the ASDeliveredVerificationCodesManager API. An example usage might look like:

struct DeliveredVerificationCodesManagerExample: View {
    @Environment(\.deliveredVerificationCodesManager) private var deliveredVerificationCodesManager

    var body: some View {
        Button("Listen for Codes") {
            Task {
                do {
                    let codes = try deliveredVerificationCodesManager.oneTimeCodes()
                    for try await code in codes {
                        handle(code: code)
                    }
                } catch DeliveredVerificationCodesManager.VerificationError.userPermissionDenied {
                    // Explaining why OTCs are needed or try without codes
                } catch DeliveredVerificationCodesManager.VerificationError.appIsNotEnabledCredentialProvider {
                    // Show UI explaining how to turn on the app as a Password Manager
                } catch {
                    // code to handle the save error
                }
            }
        }
    }
}

No APIs match your filter.

← More in Privacy, Security & Identity