Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I use the apple to log in, the selection box will pop up. I choose to use the password to continue and the prompt is not complete

Tags:

ios

ios13

iOS13 (beta) Apple Login error

@available(iOS 13.0, *)
    func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
        // Handle error.
        crprint(error.localizedDescription)
    }

Failed to complete operation. (com.apple.AuthenticationServices.AuthorizationError error 1000.)

like image 599
yiruchuxia Avatar asked Sep 05 '19 09:09

yiruchuxia


People also ask

How do I stop Apple asking for my password?

Tap your name. Tap Media & Purchases. Tap Password Settings, then choose the setting that you want.

Why does Apple Store keep asking for password?

The repeated appearance of password queries by the App Store can indicate that some apps need iCloud login. App Store keeps asking for password if you have downloaded apps that require iCloud login before the update.


1 Answers

In my case i needed to first check ASAuthorizationPasswordProvider, then, if there are no stored credential, use ASAuthorizationAppleIDProvider. For this case i had to make some crunches. Code below:

// Initial point   
public func fire(appleIDCompletion: @escaping AppleIDServiceCompletion) {
    self.completion = appleIDCompletion

    let requestPassword = ASAuthorizationPasswordProvider().createRequest()
    performRequest(requestPassword)
}

// help function
private func performRequest(_ request: ASAuthorizationRequest) {
    let controller = ASAuthorizationController(authorizationRequests: [request])
    controller.delegate = self
    controller.presentationContextProvider = self
    controller.performRequests()
} 

// delegate
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
    if let e = error as? ASAuthorizationError {
        switch e.code {
        case .canceled:
            trace("User did cancel authorization.")
            return
        case .failed:
            trace("Authorization failed.")
        case .invalidResponse:
            trace("Authorization returned invalid response.")
        case .notHandled:
            trace("Authorization not handled.")
        case .unknown:
            if controller.authorizationRequests.contains(where: { $0 is ASAuthorizationPasswordRequest }) {
                trace("Unknown error with password auth, trying to request for appleID auth..")

                let requestAppleID = ASAuthorizationAppleIDProvider().createRequest()
                requestAppleID.requestedScopes = [.email, .fullName]
                requestAppleID.requestedOperation = .operationImplicit
                performRequest(requestAppleID)
                return
            } else {
                trace("Unknown error for appleID auth.")
            }
        default:
            trace("Unsupported error code.")
        }
    }

    completion?(.rejected(error))
}

Works like a charm 🔥

like image 119
Nik Kov Avatar answered Nov 16 '22 01:11

Nik Kov