GoogleApisForiOSComponents
GoogleApisForiOSComponents copied to clipboard
Xamarin.Google.iOS.SignIn 5.0.2.4 does not call ISignInUIDelegate methods
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);
}
}
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?
Surprisingly using SharedInstance.Delegate = this instead of SharedInstance.SignedIn += OnSignedIn started to work for me, where this implements ISignInDelegate.