Goo*_*ose 7 android monogame xamarin google-play-services google-play-games
我正在使用Xamarin开发使用Google Play游戏服务的Android游戏.我正在使用Genymotion Android Emulator进行测试.我遇到了一个似乎是Google Play或Xamarin实施中的错误的问题.
如果我退出Google帐户,则对IGoogleApiClient.IsConnected()的调用将继续返回true(即使我已经明确注销).如果我然后尝试使用该API对象,我会得到以下异常:
java.lang.SecurityException:调用API时未登录
例如,如果在注销后执行,则以下代码会导致上述异常:
public void StartNewMatch()
{
if (!mGoogleApiClient.IsConnected)
{
return;
}
Intent intent = GamesClass.TurnBasedMultiplayer.GetSelectOpponentsIntent(mGoogleApiClient, 1, 1, true);
StartActivityForResult(intent, RC_SELECT_PLAYERS);
}
Run Code Online (Sandbox Code Playgroud)
我正在Google Play游戏收件箱(匹配选择器)中退出; 如下图所示.
有没有人遇到过这个?我错过了什么吗?有任何解决方法吗?
注意:只有通过Google的用户界面退出时才会出现这种情况.如果我手动签署用户,等等mGoogleApiClient.Disconnect(),问题就不会发生; mGoogleApiClient.IsConnected()现在返回false(如预期的那样).



fre*_*dom 18
为了保持登录状态同步,你必须正确实现onActivityResult.
这应该看起来如下:
注意:这是java代码,我不确定这将如何使用Xamarin,但希望你应该能够弄明白:)
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent data) {
// check for "inconsistent state"
if ( responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && requestCode == <your_request_code_here> ) {
// force a disconnect to sync up state, ensuring that mClient reports "not connected"
mGoogleApiClient.disconnect();
}
}
Run Code Online (Sandbox Code Playgroud)
注意:只需确保在代码中替换您使用的请求代码.您可能还需要检查多个请求代码.
| 归档时间: |
|
| 查看次数: |
1655 次 |
| 最近记录: |