I've been using ASAuthorizationController
and ASAuthorizationSecurityKeyPublicKeyCredentialProvider
to add security key support to our app. The general flow is:
ASAuthorizationController
callsperformRequest
and brings up Apple's UI that prompts the user to use a security key.ASAuthorizationController
calls a completion handler (eitherdidCompleteWithAuthorization
ordidCompleteWithError
) to indicate to the delegate that authorization is complete.
We should be able to immediately start another authorization request after the completion handler is called, but instead I get this error:
Error Domain=com.apple.AuthenticationServices.AuthorizationError Code=1004 "Request already in progress for specified application identifier." UserInfo={NSLocalizedFailureReason=Request already in progress for specified application identifier.}
Adding a 10ms or 100ms delay (testing on an iPhone 11 and running Xcode 14 on M1 Mac) after the completion handler still throws this error. Adding a 1s delay resolves the issue. The error makes me think that the UI prompting for user action is running async to the authorization logic and isn't fully dismissed when the completion handler is called.
Is there a better way to fix this issue that doesn't involve adding a delay?