Contents

prepareOneTimeCodeCredentialList(for:)

Prepares the interface to display a list of one-time passcodes (OTPs) that people can select from.

Declaration

func prepareOneTimeCodeCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier])

Parameters

  • serviceIdentifiers:

    An array of service identifiers that provide a hint about the service that people need an OTP for.

Mentioned in

Overview

Discussion

The system calls this method to tell your extension’s view controller to prepare a list of OTPs to present. After calling this method, the system presents the view controller to the person.

Use the given serviceIdentifiers array to filter or prioritize the credentials to display. The service identifier array might be empty, but your extension still shows credentials that the person can select from.

Items in the array with lower indices represent more specific identifiers for which an OTP’s requested. For example, if the array contains identifiers [m.example.com, example.com], the item m.example.com represents the more specific service that requires an OTP.

When someone selects an OTP displayed by your view controller, represent the passcode as an ASOneTimeCodeCredential and pass it to the system by calling completeOneTimeCodeRequest(using:completionHandler:):

let credential = ASOneTimeCodeCredential(code: otpCode)
await extensionContext.completeOneTimeCodeRequest(using: credential)

Always provide a way for someone to cancel the operation from your view controller, for example, by including a Cancel button in the navigation bar. When someone cancels the operation, call cancelRequest(withError:), using the error domain ASExtensionErrorDomain and code userCanceled:

let error = NSError(domain: ASExtensionErrorDomain,
                    code: ASExtensionError.userCanceled.rawValue)
extensionContext.cancelRequest(withError: error)

The system dismisses your view controller after you call either the completion or cancellation method.

See Also

Selecting a credential