Java Xamarin Forms 中 GoogleClientManager 注销的 Lang 非法状态异常
Java Lang Illegal State Exception for GoogleClientManager Logout in Xamarin Forms
我正在使用 https://www.pujolsluis.com/google-client-plugin-for-xamarin/ 进行 google 登录 xamarin 表单。登录和注销方法都可以正常工作;但是我必须在成功 login.After 从第二次开始打开应用程序后隐藏登录页面,注销方法抛出 java.Lang.IlegalStateException<Timeout exceeded getting exception details>
,不能 logout.Active 令牌是 null.How 来处理这个异常?如何从第二次退出成功?
登录:
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 客户端,如异常消息所述。
Google Client Illegal State Exception Screenshot
要解决此问题,您可以做两件事,修复应用程序中的逻辑以保持注销状态,这样您就不会在用户实际上不再登录时尝试注销。或者您可以启用 ActiveToken 并在尝试注销之前添加一个 if 语句以验证它是否为 null 您可以按照项目 repo 入门指南中的步骤执行此操作:https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md
Activate ActiveToken Google Client Plugin Guide Screenshot
我正在使用 https://www.pujolsluis.com/google-client-plugin-for-xamarin/ 进行 google 登录 xamarin 表单。登录和注销方法都可以正常工作;但是我必须在成功 login.After 从第二次开始打开应用程序后隐藏登录页面,注销方法抛出 java.Lang.IlegalStateException<Timeout exceeded getting exception details>
,不能 logout.Active 令牌是 null.How 来处理这个异常?如何从第二次退出成功?
登录:
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 客户端,如异常消息所述。
Google Client Illegal State Exception Screenshot
要解决此问题,您可以做两件事,修复应用程序中的逻辑以保持注销状态,这样您就不会在用户实际上不再登录时尝试注销。或者您可以启用 ActiveToken 并在尝试注销之前添加一个 if 语句以验证它是否为 null 您可以按照项目 repo 入门指南中的步骤执行此操作:https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md
Activate ActiveToken Google Client Plugin Guide Screenshot