iOS8 GameKit TurnBasedMatch playerID已弃用

iOS8 GameKit TurnBasedMatch playerID已弃用

问题描述:

我正在iOS8中使用GameCenter/GameKit来构建TurnBasedMatch。我很困惑如何识别当前玩家(即当前在iPhone上运行的应用程序)是否是现在的玩家。我遇到这个问题的原因是苹果文档说在iOS8中不推荐使用GKTurnBasedParticipant.playerID。iOS8 GameKit TurnBasedMatch playerID已弃用

我曾经做到以下几点: - 当GameCenter的验证: (1)存储当前playerID本地 (2)负载电流匹配 (3)检查是否Match.currentParticipant的playerID本地存储playerID相匹配,并且如果是,则允许玩家轮流使用

现在在iOS8中 - currentParticipant(这是一个GKTurnBasedParticipant)有playerID弃用。那么我怎么知道当前的参与者是否真的是本地球员呢?

你不需要存储playerID来检查身份。当地playerID可以随时访问:

[GKLocalPlayer localPlayer].playerID 

至于如何使用playerID现在,它的过时,该属性仅从GKTurnBasedParticipantGKPlayer移动。这不会影响我之前粘贴的代码,但它会影响您访问match.participants的方式。因此,对于任何给定的球员,访问它在iOS8上的方法是:

GKTurnBasedParticipant *p1 = (GKTurnBasedParticipant *)self.match.participants[index]; 
p1.player.playerID 

正如你所看到的,你只需要一个.player添加到您当前密码。