gpt4 book ai didi

ios - 为什么 Social.localUser.Authenticate 在 Unity 应用程序没有互联网连接时会导致崩溃?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:57 26 4
gpt4 key购买 nike

有互联网连接

一切都完美无缺。不存在导致崩溃的内存问题。

没有互联网连接

应用程序进入菜单屏幕,最终由于内存不足而崩溃。

我断定问题出在下面这行代码

Social.localUser.Authenticate

当我注释掉上面的行时,内存问题在没有互联网连接时就消失了。

这是我的相关代码

void Start () 
{
Social.localUser.Authenticate(ProcessAuthentication);
}

public void ProcessAuthentication(bool success)
{
if(success)
Debug.Log ("Authenticated");
else
Debug.Log ("Failed to authenticate");
}

导致崩溃

2016-02-27 15:46:37.131 BrickBall[449:60670] Received memory warning.
WARNING -> applicationDidReceiveMemoryWarning()
2016-02-27 15:46:37.302 BrickBall[449:60670] Received memory warning.
WARNING -> applicationDidReceiveMemoryWarning()
2016-02-27 15:46:37.349 BrickBall[449:60670] Received memory warning.
WARNING -> applicationDidReceiveMemoryWarning()
2016-02-27 15:46:37.437 BrickBall[449:60670] Received memory warning.
WARNING -> applicationDidReceiveMemoryWarning()
Message from debugger: Terminated due to memory issue

为什么当没有互联网连接时,这行代码会导致内存不足崩溃?

最佳答案

我的猜测是您最终需要与 Unity 对话。当没有网络连接时,游戏中心将使用缓存的凭据来报告它已成功连接到服务器并通过身份验证,即使它没有。我有一个 bug 未解决——并且正在与 Apple 就此进行讨论。此行为允许某些游戏类型即使在没有网络时也能继续,然后在连接恢复时同步。但是,我遇到了一些问题,我认为我可以做一些事情,因为 GC 说它已经过身份验证,但我真的做不到,因为它确实没有。 :/

这意味着应用必须处理三种情况:

  • 成功通过 GC 验证
  • GC 认证失败
  • 身份验证失败,但根据缓存数据报告为成功

Unity 可能无法处理第三种情况。要确认或反驳这一点,请尝试以下操作:

确认 Unity 确实干净地处理了身份验证失败

  1. 建立连接

  2. 退出游戏中心

  3. 中断连接(飞行模式等)

  4. 重试您的应用

我希望此时 success 为 false 并干净地运行。

如果这按预期工作,我会与 Unity 讨论他们如何处理 Game Center 在断开连接的情况下报告(缓存的)成功。

编辑2:

我不得不回过头来查看我的代码,看看我是如何加固它的。场景是:当完全断开连接和/或处于飞行模式时,Game Center 显示“欢迎回来”消息并且 localPlayer.authenticated 设置为 YES...但是,设置了错误代码并提示无法连接。

我打开了 bug 22232706,“[GKLocalPlayer localPlayer].authenticated 在设置任何身份验证处理程序后总是返回 true,”并且仍在进行讨论。 Apple 证实了这一行为,但表示这是有意为之。

下面是我如何强化我的身份验证处理程序来处理这种情况。它不会帮助你,因为 Unity 正在为你处理这个,但我认为其他读者可能会觉得这有帮助。 (TL;DR 版本是:始终始终始终首先检查错误代码,然后再检查.authenticated 或检查是否viewController 已设置)

[localPlayer setAuthenticateHandler:^(UIViewController *loginViewController, NSError *error)
{
//Note: this handler fires once when you call setAuthenticated, and again when the user completes the login screen (if necessary)

//did we get an error? Could be the result of either the initial call, or the result of the login attempt
//Very important: ALWAYS check `error` before checking for a viewController or .authenticated.
if (error)
{
//Here's a fun fact... even if you're in airplane mode and can't communicate to the server,
//when this call back fires with an error code, localPlayer.authenticated is sometimes set to YES despite the total failure. ><
//combos seen so far:
//error.code == -1009 -> authenticated = YES
//error.code == 2 -> authenticated = NO
//error.code ==3 -> authenticated = YES

if ([GKLocalPlayer localPlayer].authenticated == YES)
{
NSLog(@"error.code = %ld but localPlayer.authenticated = %d", (long)error.code, [GKLocalPlayer localPlayer].authenticated);
}

//Do stuff here to disable network play, disable buttons, warn users, etc.
return;
}

//if we received a loginViewContoller, then the user needs to log in.
if (loginViewController)
{
//the user isn't logged in, so show the login screen.
[rootVC2 presentViewController:loginViewController animated:NO completion:^
{

//was the login successful?
if ([GKLocalPlayer localPlayer].authenticated)
{
//enable network play, or refresh matches or whatever you need to do...
}
}];
}

//if there was not loginViewController and no error, then the user is alreay logged in
else
{
//the user is already logged in
//refresh matches, leaderboards, whatever you need to do...
}

}];

关于ios - 为什么 Social.localUser.Authenticate 在 Unity 应用程序没有互联网连接时会导致崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35674950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com