3

当从 MatchmakerViewController 切换到 GKMatchmaker 时,我在不同设备(均为 iPhone 5s)上运行的两个沙盒游戏中心帐户不再连接到同一场比赛。两者都显示 expectedPlayerCount 仍高于 0。

我按照 RayWenderlich 教程使用游戏中心创建多人游戏。它应该是实时的,并且是这样工作的。使用 GKMatchmakerViewController 一切正常(自动匹配和邀请)。但是,一旦我切换了一个代码块,它就不再起作用了。我已经摆弄了一段时间了,苹果文档似乎对我一点帮助都没有。任何人都知道我可能需要做额外的事情吗?

func findMatchWithMinPlayers(minPlayers: Int, maxPlayers: Int, viewController: UIViewController, delegate: GameKitHelperDelegate) {

    if enableGameCenter == false {
        return
    }

    matchStarted = false
    gkMatch = nil
    gkDelegate = delegate
    viewController.dismissViewControllerAnimated(false, completion: nil)

    var request = GKMatchRequest()
    request.minPlayers = minPlayers
    request.maxPlayers = maxPlayers

    if pendingRecipients != nil {
        request.recipients = pendingRecipients!
    }

    GKMatchmaker.sharedMatchmaker().findMatchForRequest(request, withCompletionHandler: { (match: GKMatch!, error: NSError!) -> Void in

        self.gkMatch = match
        self.gkMatch?.delegate = self
        println(match)
        if self.matchStarted == false && match.expectedPlayerCount == 0 {
            self.lookupPlayers()
        }
    })
}

这与工作之间的唯一区别是它具有 GKMatchmaker 而不是 GKMatchmakerViewController 和 Delegate。

4

0 回答 0