xamarin - Xamarin 表单中 GoogleClientManager 注销的 Java 语言非法状态异常
问题描述
我正在使用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;
}
解决方案
您收到此异常是因为您尝试注销不再连接的谷歌客户端,因为异常状态的消息。
要解决这个问题,您可以做两件事,修复应用程序中的逻辑以保持注销状态,这样您就不会在用户实际上不再登录时尝试注销。或者,您可以启用 ActiveToken 并在尝试注销之前添加一个 if 语句以验证它是否为空,您可以按照项目 repo 的入门指南中的步骤进行操作:https ://github.com/CrossGeeks /GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md
推荐阅读
- mongodb - Mongo DB 连接延迟
- angular - 如何以角度获得Activatedroute
- python - 如何在 python 中发布带有请求的有效负载?
- influxdb - 在 influxdb 中,“tag”消耗的存储空间是否比“field”少?
- erlang - 如何从 Erlang 的其他目录访问 .beam 文件?
- bash - How to capture output of df -h --total - Bash
- c++ - c++程序计算求解分段函数(涉及指针)
- reactjs - 将uri转换为文件反应本机js
- f# - 为什么 F# 交互式控制台不认为“assert (2=3)”是错误的?
- java - 同一事务中不同 CDI 事件的执行顺序