Google signin does not call delegate method after success

I use the Google SDK to log in to Google, but after entering the email address and password

in viewDidLoad I added a delegate

// set delegates to log in to Google

    [GIDSignIn sharedInstance].delegate = self;
    [GIDSignIn sharedInstance].uiDelegate = self;

-(void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error{
}

did not call. where the problem does not reach

when I enter the email address and password of the user, I get this

enter image description here

this method is called and indicates that the error is zero.

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {

}
+5
source share
5 answers

Add the following code to the AppDelegate.m file

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{



    return [[GIDSignIn sharedInstance] handleURL:url
                               sourceApplication:sourceApplication
                                      annotation:annotation];
    }
+2
source

, , GIDSignInUiDelegate, , , GIDSignInDelegate . GIDSignIn:

@protocol GIDSignInDelegate <NSObject>        
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error;

@protocol GIDSignInUIDelegate <NSObject>
@optional
- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error;

uiDelegate UIViewController, .

, , AppDelegate GIDSignInDelegate, ! : , ViewController delegate of GIDSignIn.sharedInstance . , :

- (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error {
    if (GIDSignIn.delegate != self) {NSLog("gotcha!")}
}
+1

AFAIK GIDSignIn :

  • delegate
  • uiDelegate

, , uiDeleagte.

0
source

I had a very similar problem, until I realized that GIDSignInDelegate was collecting garbage between starting an entry and receiving a callback. Just saving the link to it in other places solved my problems. (supposedly Google uses a weak link)

0
source

I have the same problem. I tried to log in as shown below.

// GDrive.swift

import GoogleSignIn
import GoogleAPIClientForREST

class GDrive: NSObject,GIDSignInDelegate,GIDSignInUIDelegate

func signIn() {
        GIDSignIn.sharedInstance().uiDelegate = self
        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().scopes = scopes
        GIDSignIn.sharedInstance().signIn()
    }

func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {
        print("Dispatch ")
    }

    func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!)
    {
        print("Present View Controller")
    }

    func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!)
    {
        print("Dismiss View Controller")
    }

    public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!)
    {
        print("Sign In")
    }
}


//ViewController.swift

class MainVC: UIViewController {

    func signInGDrive() {
          let gClient:GDrive = GDrive() // this line has weak reference
          gClient.signIn()

    }

}

After moving the gClient variable over the file, the delegate function is called. Final working code:

//ViewController.swift

class MainVC: UIViewController {
    let gClient:GDrive = GDrive() 
    func signInGDrive() {

          gClient.signIn()

    }

}

Thanks @akroy.

0
source

All Articles