我使用https://www.pujolsluis.com/google-client-plugin-for-xamarin/在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 Client Illegal State Exception Screenshot
为了解决这个问题,你可以做两件事情,修复您的应用程序坚持登出状态的逻辑,所以你不要试图注销当用户实际上没有登录了。或者你可以让ActiveToken并试图注销,以验证它是否为空之前添加if语句或没有,你可以通过以下对项目回购的入门指南中的步骤操作:https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md