简体   繁体   English

Firebase Google SignIn Ios 更新文档不起作用

[英]Firebase Google SignIn Ios updated Documentation not working

I've been trying to integrate google sign into my ios project but as they have updated their API I Can't find the solution as everyone is using GIDSignIn.sharedInstance()?.delegate and it doesn't exist anymore.我一直在尝试将 google 登录集成到我的 ios 项目中,但是由于他们更新了他们的 API,我找不到解决方案,因为每个人都在使用 GIDSignIn.sharedInstance()?.delegate 并且它不再存在。

Documentation文档

so what I understood from the documentation is:所以我从文档中了解到的是:

after setting up GoogleSignIn dependency->设置 GoogleSignIn 依赖项后->

  1. added URL Schemes.添加了 URL 方案。

  2. Implement the application:openURL:options: method of your app delegate.实现应用程序委托的 application:openURL:options: 方法。


    @available(iOS 9.0, *)
   
        func application(_ application: UIApplication, open url: URL,
                    options: [UIApplication.OpenURLOptionsKey: Any])
     -> Bool {
     return GIDSignIn.sharedInstance.handle(url)
   }
  1. Added a view in Storyboard and assigned class GIDSignInButton.在 Storyboard 中添加了一个视图并分配了 GIDSignInButton 类。

4.Pass the presenting view controller and client ID for your app to the Google Sign In sign-in method and create a Firebase auth credential from the resulting Google auth token: (documentation) 4.将应用程序的呈现视图控制器和客户端 ID 传递给 Google Sign In 登录方法,并从生成的 Google 身份验证令牌创建 Firebase 身份验证凭据:(文档)

(not quite sure where to add this, Right now I am adding it to the ViewDidLoad method of my loginViewController , without changing anything) (不太确定在哪里添加这个,现在我将它添加到我的 loginViewController 的 ViewDidLoad 方法中,没有改变任何东西)

 guard let clientID = FirebaseApp.app()?.options.clientID else { return }
    
    // Create Google Sign In configuration object.
    let config = GIDConfiguration(clientID: clientID)
    
    // Start the sign in flow!
    GIDSignIn.sharedInstance.signIn(with: config, presenting: self) { [unowned self] user, error in
    
      if let error = error {
        // ...
        return
      }
    
      guard
        let authentication = user?.authentication,
        let idToken = authentication.idToken
      else {
        return
      }
    
      let credential = GoogleAuthProvider.credential(withIDToken: idToken,
                                                     accessToken: authentication.accessToken)
    
      // ..AuthCode.
    }



5. Then finally adding authentication below credential :


    Auth.auth().signIn(with: credential) { authResult, error in
        if let error = error {
          let authError = error as NSError
          if isMFAEnabled, authError.code == AuthErrorCode.secondFactorRequired.rawValue {
            // The user is a multi-factor user. Second factor challenge is required.
            let resolver = authError
              .userInfo[AuthErrorUserInfoMultiFactorResolverKey] as! MultiFactorResolver
            var displayNameString = ""
            for tmpFactorInfo in resolver.hints {
              displayNameString += tmpFactorInfo.displayName ?? ""
              displayNameString += " "
            }
            self.showTextInputPrompt(
              withMessage: "Select factor to sign in\n\(displayNameString)",
              completionBlock: { userPressedOK, displayName in
                var selectedHint: PhoneMultiFactorInfo?
                for tmpFactorInfo in resolver.hints {
                  if displayName == tmpFactorInfo.displayName {
                    selectedHint = tmpFactorInfo as? PhoneMultiFactorInfo
                  }
                }
                PhoneAuthProvider.provider()
                  .verifyPhoneNumber(with: selectedHint!, uiDelegate: nil,
                                     multiFactorSession: resolver
                                       .session) { verificationID, error in
                    if error != nil {
                      print(
                        "Multi factor start sign in failed. Error: \(error.debugDescription)"
                      )
                    } else {
                      self.showTextInputPrompt(
                        withMessage: "Verification code for \(selectedHint?.displayName ?? "")",
                        completionBlock: { userPressedOK, verificationCode in
                          let credential: PhoneAuthCredential? = PhoneAuthProvider.provider()
                            .credential(withVerificationID: verificationID!,
                                        verificationCode: verificationCode!)
                          let assertion: MultiFactorAssertion? = PhoneMultiFactorGenerator
                            .assertion(with: credential!)
                          resolver.resolveSignIn(with: assertion!) { authResult, error in
                            if error != nil {
                              print(
                                "Multi factor finanlize sign in failed. Error: \(error.debugDescription)"
                              )
                            } else {
                              self.navigationController?.popViewController(animated: true)
                            }
                          }
                        }
                      )
                    }
                  }
              }
            )
          } else {
            self.showMessagePrompt(error.localizedDescription)
            return
          }
          // ...
          return
        }
        // User is signed in
        // ...
    }

The auth code is taken from the documentation, it's not updated and surely I won't need this many details just UId.授权代码取自文档,它没有更新,当然我不需要这么多细节只是 UId。

I don't know what the problem is but it doesn't seem to work.我不知道问题是什么,但它似乎不起作用。 On running, just Google sign-in button appears and on clicking it nothing happens运行时,只出现谷歌登录按钮,点击它没有任何反应

It appears that there is some problem with GIDSignInButton. GIDSignInButton 似乎存在一些问题。 Made A custom button and it is working fine制作了一个自定义按钮,它工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM