GIDSignIn 方法中的配置参数去了哪里?

问题描述 投票:0回答:3

我正在用google和facebook授权重建pet IOS项目。谷歌流程曾经是这样的:

GIDSignIn.sharedInstance.signIn(with: config, presenting: presentingViewController) {

        user, error in ///bla bla bla }

但是当重新下载 GoogleSignIn 包时,xcode 开始显示错误。并且谷歌授权流程更改为

GIDSignIn.sharedInstance.signIn(withPresenting: presentingViewController) {

            user, error in ///bla bla bla }

问题是当我以这种“新”方式进行身份验证时,我的应用程序崩溃并显示消息

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No active configuration.  Make sure GIDClientID is set in Info.plist.'

谷歌文档和 github 代表中也没有信息。请帮忙!

ios swift oauth-2.0 google-signin gidsignin
3个回答
2
投票

功能已更新,

with: config
参数已删除。 googleservice-info 中的 Client_ID 值应添加到 info.plist 作为 GIDClientID 键。你的功能应该是

func googleSign(){
  
    
    guard let presentingVC = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first?.rootViewController else {return}
    // Start the sign in flow!
    GIDSignIn.sharedInstance.signIn(withPresenting: presentingVC) { user, error in
        if let error = error {
            print(error.localizedDescription)
            return
          }

          guard let authentication = user?.authentication, let idToken = authentication.idToken
          else {
            return
          }

          let credential = GoogleAuthProvider.credential(withIDToken: idToken,
                                                         accessToken: authentication.accessToken)
        self.showCustomAlertLoading = true
        Auth.auth().signIn(with: credential) { authResult, error in
            guard let user = authResult?.user, error == nil else {
                self.signUpResultText = error?.localizedDescription ?? "Error Occured"
                DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
                    self.showCustomAlertLoading = false
                })
                return}
            self.signUpResultText = "\(user.email!)\nSigning Succesfully"
            self.isSignUpSucces = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: {
                self.showCustomAlertLoading = false
                DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
                    self.navigateHome = true
                })
            })
            print("\(user.email!) signed****")
            
        }
    }
}

1
投票

确保您正在下载版本

6.0.2
以获得
GIDSignIn.sharedInstance.signIn(with: presenting: callback)


0
投票

我不建议将

CLIENT_ID
添加到您的 Info.plist 中。根据Firebase官方文档,他们建议直接从
GoogleService-Info
文件获取。

想象一个场景,您有多个 Firebase 项目,每个项目都有不同的

GoogleService-Info
用于暂存、测试、生产,所有这些都在同一个项目中。在这种情况下,您可能会遇到错误,或者您必须根据环境更改每个构建的 Info.plist,因为每个文件都有自己的
CLIENT_ID

你应该只使用:

guard let clientID = FirebaseApp.app()?.options.clientID else { return }
let config = GIDConfiguration(clientID: clientID)

GIDSignIn.sharedInstance.configuration = config

GIDSignIn.sharedInstance.signIn(withPresenting: viewController) { [unowned self] signInResult, error in
   // bla, bla, bla
}

https://firebase.google.com/docs/auth/ios/google-signin

© www.soinside.com 2019 - 2024. All rights reserved.