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

后端 未结 7 2888
刺人心
刺人心 2021-02-20 05:40

iOS13 (beta) Apple Login error

@available(iOS 13.0, *)
    func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error)         


        
7条回答
  •  -上瘾入骨i
    2021-02-20 06:29

    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

提交回复
热议问题