Google Sign-In via Firebase:GIDSignInDelegate不符合ViewController [英] Google Sign-In via Firebase: GIDSignInDelegate does not conform to ViewController

查看:214
本文介绍了Google Sign-In via Firebase:GIDSignInDelegate不符合ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Google Sign-In引入到我的应用中,虽然Google和Firebase文档都足够透彻,但是我所做的只是他们的建议还不够...我仍然收到此错误。希望这可以帮助其他人在实现SDK时找到问题的解决方案....感谢您提前审查这个矮胖的: ://i.stack.imgur.com/TOl6S.pngrel =noreferrer>



以下是



PS 我没有将GIDSignInDelegate添加到AppDelegate,因为我我正在计划我的VC来处理登录逻辑,正如你将会在下面看到的那样... / p>

 类LoginVC:UIViewController,UIViewControllerTransitioningDelegate,UITextViewDelegate,UITextFieldDelegate,GIDSignInDelegate,GIDSignInUIDelegate {

覆盖f unc viewDidLoad(){
super.viewDidLoad()
let ref = Firebase(url:https://MYAPPID.firebaseio.com)
GIDDSignIn.sharedInstance()。delegate = self
GIDSignIn.sharedInstance()。uiDelegate = self
GIDSignIn.sharedInstance()。signInSilently()//如果用户最近已经过认证
}

  //实现所需的GIDSignInDelegate方法
func googleSignIn(signIn:GIDSignIn!,didSignInForUser user: (错误== nil){
// Auth with Firebase
let userId = user.userID
let idToken = user。 authentication.idToken
let fullName = user.profile.name
let givenName = user.profile.givenName
let familyName = user.profile.familyName
let email = user.profile.email
ref.authWithOAuthProvider(google,token:user.authentication.accessToken,withCompletionBlock:{(error,authData)in
//用户已经登录!
} else {
print(\(error.localizedDescription))
}
}


func googleSignOut(){
GIDSignIn.sharedInstance()。signOut()
ref.unauth()
}

//实现所需的GIDSignInDelegate方法和Unauth当与Google
断开时,func signIn(signIn:GIDSignIn!,didDisconnectWithUser user:GIDGoogleUser !, withError error:NSError!){
ref.unauth()
}


// IBAction来处理登录过程
@IBAction func googleButtonPressed(sender:TKTransitionSubmitButton!){
GIDSignIn.sharedInstance()。signIn()
}

折叠?很抱歉,对于那些漫长的人...但是我已经完成了Firebase指南所建议的所有内容,这意味着Google文档中AppDelegate的逻辑在ProfileVC中都是存在的。任何指针?

解决方案

这是说你的类没有为你的 GIDSignInDelegate 。在Swift 3中,方法的名字有很大的改变。所以你的新方法是:

lockquote
public func sign(_ signIn:GIDSignIn !, didSignInFor用户:
GIDGoogleUser !,有错误错误:NSError!)

请检查图书馆的屏幕截图。所以 In 在新的swift 3约定的方法或类的命名中是缺少的。


I'm introducing Google Sign-In to my app and whilst both Google and Firebase documentation is thorough enough, what I have done as they suggested is not sufficient... I am still getting this error. Hopefully this will help others with finding a solution to the problem when implementing their SDK....thanks in advance for reviewing this chunky one:

Here's the Firebase guide and the Google guide:

So

  1. Added Google to podfile - CHECK
  2. Added line into Bridging-Header - CHECK
  3. Added GoogleService-Info.plist & bundle identifier & reversed client ID to URL schemes - CHECK
  4. App Delegate has the following, with no errors but I notice there are likely to be conflicts between Facebook login (working correctly) and newly Google, which I've no idea how to handle together:

    P.S. I have NOT added GIDSignInDelegate to AppDelegate here because I am planning for my VC to handle the login logic, as you will see below...

  5. LoginVC ViewController code here:

    class LoginVC: UIViewController, UIViewControllerTransitioningDelegate, UITextViewDelegate, UITextFieldDelegate, GIDSignInDelegate, GIDSignInUIDelegate {
    
        override func viewDidLoad() {
        super.viewDidLoad()
        let ref = Firebase(url: "https://MYAPPID.firebaseio.com")
        GIDDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().signInSilently()  // for if the user has recently been authenticated
        }
    

Then this, which from what I can see... should be everything Google needs to talk to Firebase:

        // Implementing the required GIDSignInDelegate methods
        func googleSignIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
            if (error == nil) {
                // Auth with Firebase
                let userId = user.userID
                let idToken = user.authentication.idToken
                let fullName = user.profile.name
                let givenName = user.profile.givenName
                let familyName = user.profile.familyName
                let email = user.profile.email
                ref.authWithOAuthProvider("google", token: user.authentication.accessToken, withCompletionBlock: { (error, authData) in
                    // User is logged in!
                })
            } else {
                print("\(error.localizedDescription)")
            }
        }


        func googleSignOut() {
            GIDSignIn.sharedInstance().signOut()
            ref.unauth()
        }

        // Implement the required GIDSignInDelegate methods and Unauth when disconnected from Google
        func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {
            ref.unauth()
        }


        // IBAction to handle the sign-in process
        @IBAction func googleButtonPressed(sender: TKTransitionSubmitButton!) {
            GIDSignIn.sharedInstance().signIn()
        }

Baffled? Sorry for the long one guys...but I've done everything the Firebase guide suggests and that means the logic in the Google doc for AppDelegate is all there in the ProfileVC. Any pointers?

解决方案

It's saying your class have not implemented required method for your GIDSignInDelegate. There are major change in name of method in Swift 3. So your new method will be

public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: NSError!)

Please check Library screen shot. So In is missing in new swift 3 convention of naming of methods or classes.

这篇关于Google Sign-In via Firebase:GIDSignInDelegate不符合ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆