我正在使用Game Center的回合制比赛来开发游戏。
我想显示所有可用匹配项的列表。我尝试使用loadMatchesWithCompletionHandler()
,但是游戏数组返回为nil
,并且错误也返回为nil
。有一些正在进行的比赛。
这是我到目前为止的内容:
func authenticateLocalUser() {
if !gameCenterAvailable { return }
let player = GKLocalPlayer.localPlayer()
if player.authenticated == false {
player.authenticateHandler = {(viewController, error) -> Void in
if viewController != nil && self.presentingViewController != nil
{
self.presentingViewController!.presentViewController(viewController!, animated: true, completion: {
GKLocalPlayer.localPlayer().registerListener(self)
GKTurnBasedMatch.loadMatchesWithCompletionHandler({games, error in
print(games)
if games != nil {
print(games!.count)
}else {
print(error)
}
})
})
} else {
if player.authenticated == true {
GKLocalPlayer.localPlayer().registerListener(self)
GKTurnBasedMatch.loadMatchesWithCompletionHandler({games, error in
print(games)
if games != nil {
print(games!.count)
}else {
print(error)
}
})
}
}
}
} else {
print("already authenticated")
}
}
创建新的匹配项时,我什至会收到
nil
(不过,它会打印出我刚刚创建的匹配项):func findMatchWith(minPlayers: Int, maxPlayers: Int) {
if !gameCenterAvailable { return }
let request = GKMatchRequest()
request.minPlayers = minPlayers
request.maxPlayers = maxPlayers
request.defaultNumberOfPlayers = 2
GKLocalPlayer.localPlayer().loadFriendPlayersWithCompletionHandler({players, error in
if error != nil {return}
request.recipients?.append(players![0])
GKTurnBasedMatch.findMatchForRequest(request, withCompletionHandler: { match, error in
if error != nil {
print(error?.localizedDescription)
return
}
print(match)
GKTurnBasedMatch.loadMatchesWithCompletionHandler({games, error in
print(games)
if games != nil {
print(games!.count)
}else {
print(error?.localizedDescription)
}
})
})
})
}
最佳答案
这不是代码。这就是在iTunes Connect中设置游戏的方式。我需要这样做:
稍后,我将尝试删除排行榜,然后查看它是否仍然有效。实际的应用没有排行榜。
我的困惑是因为我没有遇到“无法识别的游戏”错误,并且我能够创建比赛,玩转弯,列出玩家的 friend ,但没有列出比赛。
关于ios - 如何列出播放器的所有可用GKTurnBasedMatches?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37172426/