更改GoogleSignIn吊舱版本时使用未声明的类型'GIDSignInUIDelegate'

时间:2019-09-19 08:57:49

标签: swift xcode google-signin

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

4 个答案:

答案 0 :(得分:3)

您必须将“ GIDSignInUIDelegate”更改为“ GIDSignInDelegate”,如GoogleSignIn文档中的示例:

https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift

答案 1 :(得分:1)

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

答案 2 :(得分:1)

无需使用var foo = ['apple', 'banana', 'carrot']; int i = 0; print(foo.map((e) => '${i++}. $e')); ,请查看以下链接以获取迁移指南:https://developers.google.com/identity/sign-in/ios/quick-migration-guide#migrating_from_versions_prior_to_v500

只需使用GIDSignInUIDelegate并将GIDSignInDelegate替换为GIDSignIn.sharedInstance().uiDelegate = self

GIDSignIn.sharedInstance()?.presentingViewController = self

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

这是我的应用因GIDSignIn.sharedInstance().handle(url)而被拒绝的地方

答案 3 :(得分:0)

不要使用GIDSignIn.sharedInstance()。uiDelegate = self和GIDSignInUIDelegate协议。仅使用GIDSignInDelegate协议,并导入GoogleUtilities .Implement 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
            }    })  }
    
}