localPlayer是否仍然通过身份验证,即使身份验证失败

Is localPlayer still authenticated, even if authentication fails

是否 a 有效,即使在身份验证错误的情况下?

GKLocalPlayer.localPlayer.authenticateHandler =
  ^(UIViewController *viewController, NSError *error)
{
  if (error)
  {
    bool a = GKLocalPlayer.localPlayer.authenticated;
  }
  else
  {

例如,当我有一个经过身份验证的播放器时,会发生这种情况,将应用程序移至后台,禁用 WiFi,然后再次将应用程序移至前台。我希望 GameCenter 只是继续使用缓存帐户?

我觉得手册有点含糊。 来自 https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html#//apple_ref/doc/uid/TP40008304-CH8-SW11:

"As soon as your game moves to the background, the value of the local player object’s authenticated property becomes and remains invalid until your game moves back to the foreground. You cannot read the value to determine if the player is still authenticated until Game Kit reauthenticates the player and calls your authentication handler. Your game must act as though there is not an authenticated player until your completion handler is called. Once your handler is called, value stored in the authenticated property is valid again."

即使身份验证失败,该值是否有效?

我在这方面与 Apple 有一个长期的 运行 错误。在正在进行的对话中,它已被关闭并重新打开。 .authenticated 是否有效的问题似乎取决于你的观点

Apple 认为这是按预期工作的,因为您已经缓存了信息,Apple 认为这些信息可以让您继续玩游戏,您可以显示排行榜等。Apple 表示 .authenticated 确实有效这个状态。我在这个论坛上看到一些开发人员同意这个观点,尽管我没有方便的链接到他们的帖子。

但在实践中,如果您在此状态下尝试执行任何后续游戏中心操作,它将失败,因为您并未真正通过身份验证。您无法保存游戏、加载比赛等。您显示的任何排行榜都将是陈旧的缓存数据。

在我看来,Apple 讨厌玩家看到他们的基础设施出现问题。因此,使用这种机制,您可以尝试通过伪造状态来推动前进,并希望问题稍后自行解决。在我的游戏中,该策略永远不会成功,并最终在 用户投入 time/effort 游戏后 无法恢复。所以,就像你上面的代码一样,我依赖于 NSError 所说的内容。如果说 "error" 那么我将玩家视为未经验证,提供 UI 提示来纠正这种情况。

我在此处记录了有关我的方法的更多详细信息: