ios – 如何为玩家列出所有可用的GKTurnBasedMatches?

我正在使用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中设置游戏的方式.我需要这样做:

>转到我的应用程序> App Store>准备提交并切换Game Center的开关
>添加我之前在“功能”下创建的排行榜

稍后,我将尝试删除排行榜,看看它是否仍然有效.实际的应用程序将没有排行榜.

我的困惑是因为我没有得到“无法识别的游戏”错误,我能够创建比赛,转弯,列出玩家的朋友,但不能列出匹配.

点赞