Logging in to Google via Firebase: GIDSignInDelegate does not match ViewController

I present the Google login for my application, and although the Google and Firebase documentation is quite complete, what I did on their suggestion is not enough ... I still get this error. Hope this helps others find a solution to the problem when implementing their SDK ... thanks in advance for watching this short one:

Error image

Here's the Firebase guide and Google guide:

So

  • Added by Google to the podfile - CHECK
  • Added line in Bridging-Header - CHECK
  • Added GoogleService-Info.plist and package ID and changed client ID to URL schemes - CHECK
  • The application manager has the following: no errors, but I noticed that there may be conflicts between the Facebook login (working correctly) and the new Google, which I have no idea how to handle together:

    Code added to AppDelegate - sorry, not written here, StackOverflow formatting hated me about this

    PS I have NOT added GIDSignInDelegate to AppDelegate here, because I plan that my VC will handle the input logic, as you will see below ...

  • LoginVC ViewController 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, that from what I see ... should be all that 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() } 

Upset? Sorry for the old guys ... but I did everything the Firebase guide offers, and that means the logic in the Google document for AppDelegate is there in ProfileVC. Any pointers?

+5
source share
5 answers

He said that your class did not fulfill the required method for your GIDSignInDelegate . There are major changes to the method name in Swift 3. So your new method will be

public func sign (_ signIn: GIDSignIn !, didSignIn For user: GIDGoogleUser !, with error Error: NSError!)

Please check the screenshot of the library. Thus, In missing from the new convention with quick 3 about method or class names. enter image description here

+5
source

I found the necessary methods by typing "func s" and doing a search in the suggestions window

Oh, I missed the Alt + Enter function in Android Studio

(BTW is for Swift 3 in Xcode 8 beta)

 func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: NSError!) { let authentication = user.authentication let credential = FIRGoogleAuthProvider.credential(withIDToken: (authentication?.idToken)!, accessToken: (authentication?.accessToken)!) let comp:FIRAuthResultCallback = { (user:FIRUser?, error:NSError?) in if error == nil { DataStorage.inst.user.id = user?.uid } } FIRAuth.auth()?.signIn(with: credential, completion: comp) } func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: NSError!) { } 
+2
source

Just replace

 func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) { if (error == nil) { // Perform any operations on signed in user here. } else { print("\(error.localizedDescription)") }} 

with

 public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { //Code } 
+1
source

Just add

#import "GoogleSignIn/GoogleSignIn.h"

into your Bridging header file and press shift + cmd + k to clear.

0
source

Go to: Link the binary to the libraries. Then click Add, then Add Another. Press "Cmd + shift + G". Then enter: "/ usr / lib". Then click on "libz.1.dylib". Click Ok to add and errors will disappear. In addition, you probably do not perform all the functions that come with this protocol. You should add the following:

 func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) { if (error == nil) { // Perform any operations on signed in user here. } else { print("\(error.localizedDescription)") } } func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) { // Perform any operations when the user disconnects from app here. // ... } 

Also, make sure you add foll. The title bar of the bridge.

 #import <GoogleSignIn/GoogleSignIn.h> 

UPDATE: GIDSignInDelegate cannot be added to the View Controller. Instead, you should add "GIDSignInUIDelegate" to the VC and try other (Gidsigndwlwgate) operations in the App Delegate. He will work.

-1
source

Source: https://habr.com/ru/post/1246026/


All Articles