google-signin-unity icon indicating copy to clipboard operation
google-signin-unity copied to clipboard

Uncaught exception: NSInvalidArgumentException: presentingViewController must be set.

Open romas34 opened this issue 4 years ago • 8 comments

Build for iOS. Second authentication via Google account leads to application crash. Steps:

  • I first log into the client with Google account;
  • do logging out;
  • log in again with Google;
  • close client (remove from memory);
  • launch the client again;
  • do logging out;
  • try login in via google again;
  • get a crash of the system;

I see an error in the logs: Uncaught exception: NSInvalidArgumentException: presentingViewController must be set.

The same system crash (same exception) can be obtained if:

  • I first log into the client with Google account;
  • Hide application;
  • go to the system settings and change system language;
  • launch application again;
  • logging out from Google accout;
  • try sign in via google again;
  • get a crash of the system;

If restart the application after that, then everything will be fine.

romas34 avatar Nov 24 '20 12:11 romas34

I had the same problem quite a number of times. Did not find out yet when and why this happens. This package is so buggy...

derwaldgeist avatar Nov 24 '20 15:11 derwaldgeist

I had the same problem quite a number of times. Did not find out yet when and why this happens. This package is so buggy...

hi,guys. did you find any solution ?

rb18 avatar Dec 15 '20 18:12 rb18

I just bought the commercial Google Signin package in the Unity Asset store, there's currently a sale going on. The developer confirmed that he will maintain it for the foreseeable future; and should he ever drop support, he would post the source code on Github. I don't trust the "official" Google package anymore.

derwaldgeist avatar Dec 15 '20 20:12 derwaldgeist

I found the solution. first of all you have to check GoogleSignIn.Configuration is null or not when you call GoogleSignIn.DefaultInstance.SignIn() or GoogleSignIn.DefaultInstance.SignOut(). If GoogleSignIn.Configuration is null you have to define it before you call GoogleSignIn.DefaultInstance.... ; Because GoogleSignIn.DefaultInstance returns you an instance and if it is null it is instantiated with confugiration again. So you have to check always your configuration. I implemented a method to initialize my configuration like that :

private void InitializeConfiguration()
 {
    if (GoogleSignIn.Configuration == null)
     {
        configuration = new GoogleSignInConfiguration
        {
            WebClientId = webClientId,
            RequestIdToken = true
        };
       GoogleSignIn.Configuration = configuration;
       GoogleSignIn.Configuration.UseGameSignIn = false;
       GoogleSignIn.Configuration.RequestIdToken = true;
       GoogleSignIn.Configuration.RequestAuthCode = true;
       GoogleSignIn.Configuration.RequestEmail = true;
       GoogleSignIn.Configuration.RequestProfile = true;
  }

} Then I call it on my methods before calling GoogleSignIn.DefaultInstance... For example :


   InitializeConfiguration();
   GoogleSignIn.DefaultInstance.SignIn().ContinueWith(
  OnAuthenticationFinished, TaskContinuationOptions.ExecuteSynchronously);

  or

     InitializeConfiguration();
     GoogleSignIn.DefaultInstance.SignOut();

So it works on my situation without any errors and bugs. Have a nice day guys :)

rb18 avatar Dec 16 '20 11:12 rb18

I found the solution. first of all you have to check GoogleSignIn.Configuration is null or not when you call GoogleSignIn.DefaultInstance.SignIn() or GoogleSignIn.DefaultInstance.SignOut(). If GoogleSignIn.Configuration is null you have to define it before you call GoogleSignIn.DefaultInstance.... ; Because GoogleSignIn.DefaultInstance returns you an instance and if it is null it is instantiated with confugiration again. So you have to check always your configuration.

This is a bit different. I also had this problem initially. This is a missing configuration issue. And that's how I solved it. But the described problem is different and have different exception.

romas34 avatar Dec 16 '20 12:12 romas34

It's still relevant for us, have you found a solution? Firebase SDK 6.15.2

atelyk avatar Mar 04 '21 10:03 atelyk

Let me share what helped me with the current issue: I've changed GoogleSignIn.mm file, specificly method GoogleSignIn_SignIn – I've put the next line before [[GIDSignIn sharedInstance] signIn]; [GIDSignIn sharedInstance].presentingViewController = UnityGetGLViewController(); image

atelyk avatar Mar 05 '21 09:03 atelyk

Your fix also worked for me. I created a PR for it, linked just above.

artoonie avatar Apr 28 '21 00:04 artoonie