Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Xamarin.Google.iOS.SignIn 5.0.2.4 does not call ISignInUIDelegate methods #629

Open
Zhangos opened this issue Oct 4, 2023 · 2 comments
Open

Comments

@Zhangos
Copy link

Zhangos commented Oct 4, 2023

Xamarin.Google.iOS.SignIn version 5.0.2.4 does not call ISignInUIDelegate methods when calling SignIn.SharedInstance.SignInUser();

 var topViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
 if (topViewController.PresentedViewController != null)
       topViewController = topViewController.PresentedViewController;
 if (topViewController is UINavigationController navigationController)
       topViewController = navigationController.TopViewController;
 Google.SignIn.SignIn.SharedInstance.PresentingViewController = topViewController;
 Google.SignIn.SignIn.SharedInstance.Delegate = new GoogleSignInDelegate(signInResponse, googleTimer);
 Google.SignIn.SignIn.SharedInstance.SignInUser();
    class GoogleSignInDelegate : NSObject, ISignInDelegate
    {
        private Timer googleTimer;
        private readonly TaskCompletionSource<WebAuthenticatorResult> signInResponse;
        public GoogleSignInDelegate(TaskCompletionSource<WebAuthenticatorResult> signInResponse, Timer googleTimer)
        {
            this.signInResponse = signInResponse;
            this.googleTimer = googleTimer;
        }
        public async void DidSignIn(SignIn signIn, GoogleUser user, NSError error)
        {
            System.Diagnostics.Debug.Write("GoogleSignInDelegate >>>>> call DidSignIn");
            if (error != null)
            {
                if (error.Code == -5)
                {
                    signInResponse?.TrySetCanceled();
                }
                else
                {
                    signInResponse?.TrySetException(new Exception(error.Description));
                }
                System.Diagnostics.Debug.Write($"GoogleSignInDelegate error>>>>> {error.Description}");
                return;
            }
            var authenticatorResult = new WebAuthenticatorResult();
            authenticatorResult.Properties.Add("code", user.ServerAuthCode);
            signInResponse?.TrySetResult(authenticatorResult);
        }
    }
@alexshikov
Copy link

I have the same issue using Google.SignIn.SignIn.SharedInstance.SignedIn += OnSignedIn. It's never called and there are no errors or warning in the console.

@Zhangos have you been able to find a workaround or some ideas why it happens?

@alexshikov
Copy link

alexshikov commented Oct 10, 2023

Surprisingly using SharedInstance.Delegate = this instead of SharedInstance.SignedIn += OnSignedIn started to work for me, where this implements ISignInDelegate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants