xcode 更改GoogleSignIn pod版本时使用未声明的类型“GIDSignInUIDelegate”

1tuwyuhd  于 2023-05-01  发布在  Go
关注(0)|答案(5)|浏览(218)

将GoogleSignIn的Pod版本从以前的版本更改为v5时出现问题。0.0.

gupuwyp2

gupuwyp21#

您必须将GIDSignInUIDelegate更改为GIDSignInDelegate,如GoogleSignIn文档中的示例:
https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift

yks3o0rb

yks3o0rb2#

GIDSignInUIDelegate协议过去需要在启动GIDSignIn.sharedInstance().signIn()的UIViewController中实现。UIViewController必须使用GIDSignIn.sharedInstance().uiDelegate = self注册自己。
GoogleSignIn 5.0.0已经改变了启动GIDSignIn.sharedInstance().signIn()的UIViewController应该使用GIDSignIn.sharedInstance()?.presentingViewController = self注册自己,显然不再需要实现不再存在的GIDSignInUIDelegate
GIDSignInDelegate仍然打算在AppDelegate中实现,AppDelegate应该使用GIDSignIn.sharedInstance().delegate = self注册自己。
另请参阅:https://developers.google.com/identity/sign-in/ios/quick-migration-guide

jbose2ul

jbose2ul3#

不需要使用GIDSignInUIDelegate,请查看此链接以获取迁移指南: www.example.com
只需使用GIDSignInDelegate并将GIDSignIn.sharedInstance().uiDelegate = self替换为GIDSignIn.sharedInstance()?.presentingViewController = self

GIDSignIn.sharedInstance().handle(url,
    sourceApplication: sourceApplication,
    annotation: annotation)

关于GIDSignIn.sharedInstance().handle(url)
这就是我的应用被拒绝UIWebView

70gysomp

70gysomp4#

不要使用GIDSignIn。sharedInstance().uiDelegate = self和GIDSignInUIDelegate协议。仅使用GIDSignInDelegate协议并导入GoogleUtilities。实现sigin方法。

import UIKit
import Firebase
import GoogleSignIn
import FirebaseAuth
import GoogleUtilities

class LoginViewController: UIViewController, GIDSignInDelegate  {
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance()?.presentingViewController = self
        
    }
    

    
    @IBAction func googleSignIn(sender: AnyObject) {
        GIDSignIn.sharedInstance().signIn()
    }
    
    
    
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        print("Google Sing In didSignInForUser")
        if let error = error {
            print(error.localizedDescription)
            return
        }
        guard let authentication = user.authentication else { return }
        let credential = GoogleAuthProvider.credential(withIDToken: (authentication.idToken)!, accessToken: (authentication.accessToken)!)// When user is signed in
        Auth.auth().signIn(with: credential, completion: { (user, error) in
            if let error = error {
                print("Login error: \(error.localizedDescription)")
                return
            }    })  }
    
}
baubqpgj

baubqpgj5#

如果你使用的是最新的谷歌唱歌sdk使用这个代码按钮操作

let signInConfig = GIDConfiguration.init(clientID: KGoogle.clientID)

GIDSignIn.sharedInstance.signIn(with: signInConfig, presenting: self) { user, error in
    guard error == nil else { return }
    guard let user = user else { return }

    if let profiledata = user.profile {
        
        let userId : String = user.userID ?? ""
        let givenName : String = profiledata.givenName ?? ""
        let familyName : String = profiledata.familyName ?? ""
        let email : String = profiledata.email
        
        if let imgurl = user.profile?.imageURL(withDimension: 100) {
            let absoluteurl : String = imgurl.absoluteString
            //HERE CALL YOUR SERVER API
        }
    }
    
}

相关问题