6
votes

i am using google sdk for google signin but after entering the email and password

in viewDidLoad i have added delegate

//set Google sign In delegates

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

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

not called . where is the issue not getting

when i am entering user email and password i am getting this

enter image description here

this method is called and showing error is null.

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

}
6
Did you get anything for this? - Jagdev Sendhav
@Sport: did you solve it? I'm having the same problem... - Goodsquirrel
@Spot and Goodsquirrel, I am facing same issue, Please let me know if u have fixed it. - Priyanka Singh

6 Answers

2
votes

Add following code in your 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];
    }
1
votes

The method that get's called is called on GIDSignInUiDelegate, while the method that is not called is called on the GIDSignInDelegate after login. Here's what the GIDSignIn header file says:

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

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

Since you have set both the uiDelegate and the delegate to your UIViewController instance, both methods should get called.

When I encountered the same problem, my mistake was, that I also set the AppDelegate to be the GIDSignInDelegate causing confusion for hours! So my advice: double check if your ViewController still is the delegate of GIDSignIn.sharedInstance when returning from sign in. E.g. set a breakpoint in the callback that get's called:

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

AFAIK GIDSignIn class has two delegate properties:

  • delegate
  • uiDelegate

The method that is not being called for you is defined in uiDeleagte's protocol.

0
votes

I was having a very similar issue, until realizing that the GIDSignInDelegate was being garbage collected between starting the signin and getting the callback. Just storing a reference to it elsewhere resolved my issues. (presumably Google uses a weak reference)

0
votes

I had the same problem. I had tried sign in like 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 gClient variable on top of the file delegate functions has been called. Final working code :

//ViewController.swift

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

          gClient.signIn()

    }

}

Thanks @akroy.

0
votes

Go To File: GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml

Replace line No 15:



<iosPod name="GoogleSignIn" version=">= 4.0.2" bitcodeEnabled="false"

With

<iosPod name="GoogleSignIn" version="~> 5.0.0" bitcodeEnabled="false"

<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Go To File: GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.h

Replace line No 18:

NSObject <GIDSignInDelegate, GIDSignInUIDelegate>

With

NSObject <GIDSignInDelegate>

<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Go To File: GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignIn.mm

Remove Line No 108,109,110

case kGIDSignInErrorCodeNoSignInHandlersInstalled:
    currentResult_->result_code = kStatusCodeDeveloperError;
    break;

Add this line after line No 194:

[GIDSignIn sharedInstance].presentingViewController =     UnityGetGLViewController();
return !useGameSignIn;

Replace line No 242:

 [[GIDSignIn sharedInstance] signInSilently];

With

 [[GIDSignIn sharedInstance] restorePreviousSignIn];

<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Go To File: GoogleSignInPlugin/Assets/Plugins/iOS/GoogleSignIn/GoogleSignInAppController.mm

Remove line no 78:

signIn.uiDelegate = gsiHandler;

Replace line No 99,100,101:

    return [[GIDSignIn sharedInstance] handleURL:url
    sourceApplication:sourceApplication
    annotation:annotation] ||

With

 return [[GIDSignIn sharedInstance] handleURL:url] ||

Replace line No 115,116,117,118,119,120:

return [[GIDSignIn sharedInstance]
 handleURL:url
sourceApplication:
options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:
options[UIApplicationOpenURLOptionsAnnotationKey]] ||

With

return [[GIDSignIn sharedInstance] handleURL:url] ||

<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

If you're seeing a "selector not recognized" runtime exception when calling a category method that is implemented in a static library, you are hitting the link-time build issue described here, and need to add the -ObjC linker flag to your project, by following these steps:


  1. In Xcode, choose View > Navigators > Show Project Navigator, or press ⌘1.
  2. Select your project under the PROJECT heading in the Project Navigator, then select the Build Settings tab.
  3. Scroll down to the Other Linker Flags build setting under the Linking collection, or type "Other Linker Flags" into the search bar.
  4. Set the value of the Other Linker Flags build setting to $(OTHER_LDFLAGS) -ObjC.