我正在使用 https://www.pujolsluis.com/google-client-plugin-for-xamarin/在xamarin表单中为谷歌登录。登录和注销方法都可以正常工作;但是登录成功后我必须隐藏登录页面。从第二次打开应用程序后,注销方法抛出java.Lang.IlegalStateException<Timeout exceeded getting exception details>
,无法注销。活动令牌为空。如何处理此异常?如何从第二次成功注销?
登录:
public IGoogleClientManager googleClientManager;
googleClientManager = CrossGoogleClient.Current;
private void google_btn_Clicked(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
googleClientManager.LoginAsync();
googleClientManager.OnLogin += OnLoginCompleted;
// CrossGoogleClient.Current.SilentLoginAsync();
// var userToken = CrossGoogleClient.Current.ActiveToken;
}
else
{
DependencyService.Get<IToast>().LongAlert("Check Connection!");
}
}
public async void OnLoginCompleted(object s,
GoogleClientResultEventArgs<GoogleUser> loginEventArgs)
{
if (loginEventArgs.Data != null)
{
GoogleUser googleUser = loginEventArgs.Data;
string google_name = googleUser.Name;
string google_mail = googleUser.Email;
Uri google_img = googleUser.Picture;
googleClientManager.OnLogin -= OnLoginCompleted;
}
}
注销:
public void Logout()
{
googleClientManager.OnLogout += OnLogoutCompleted;
googleClientManager.Logout(); // throws exception from secondtime after hiding loginpage
}
private void OnLogoutCompleted(object sender, EventArgs loginEventArgs)
{
googleClientManager.OnLogout -= OnLogoutCompleted;
}
您收到此异常是因为您正在尝试注销不再连接的Google客户端,因为异常消息状态
。谷歌客户端非法状态异常屏幕截图
要解决此问题,您可以做两件事,修复应用程序中的逻辑以保持注销状态,这样您就不会在用户实际不再登录时尝试注销。或者,您可以启用 ActiveToken 并在尝试注销之前添加 if 语句以验证它是否为 null,您可以按照项目存储库入门指南中的步骤执行此操作:https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md
激活活动令牌谷歌客户端插件指南截图