Contents

VerifyIdentityWithWalletButton

A type that displays a button to present the identity verification flow.

Declaration

@MainActor @preconcurrency struct VerifyIdentityWithWalletButton<Fallback> where Fallback : View

Overview

Use this structure as the SwiftUI equivalent to PKIdentityButton. The system allows one in-progress identity request at a time. Otherwise, it returns a PKIdentityError.Code.requestAlreadyInProgress error.

This example shows an implementation of the Verify Identity with Wallet button. For more information, see Requesting identity data from a Wallet pass.

// Create an identity request.
func createRequest() -> PKIdentityRequest {
    let descriptor = PKIdentityDriversLicenseDescriptor()
    descriptor.addElements([.age(atLeast: 18)],
                            intentToStore: .willNotStore)
    descriptor.addElements([.givenName, .familyName, .portrait],
                            intentToStore: .mayStore(days: 30))

    let request = PKIdentityRequest()
    request.descriptor = descriptor
    // The merchant ID you configured in your Apple Developer account.
    request.merchantIdentifier = <YOUR_MERCHANT_ID> 
    // The nonce your server generates.
    request.nonce = <YOUR_NONCE_VALUE> 
}
// Show the Verify Identity with Wallet button and handle the identity request result.
@ViewBuilder var verifiyIdentityButton: some View {
    VerifyIdentityWithWalletButton(
        .verifyIdentity,
        request: createRequest(),
    ) { result in
        switch result {
        case .success(let document):
            // Securely transfer the document to the server for decryption and verification.
        case .failure(let error):
            switch error {
            case PKIdentityError.cancelled:
                // Handle the cancellation error.
            default:
                // Handle other errors.
            }
        }
    } fallback: {
        // Verify the person's identity another way.
    }
}

Topics

Creating the button

See Also

Identity sheet interactions and authorization