如何快速接受Game Center邀请

时间:2014-11-21 18:40:19

标签: swift game-center

我有一些麻烦让swift中的邀请接受。

有人可以帮我正确编码吗?这是我的

GKMatchmaker.sharedMatchmaker().matchForInvite(Invitation!, completionHandler = {(InvitedMatch:GKMatch!, error: NSError!) -> Void in
        if InvitedMatch != nil {
            myMatch=match

            LocalGame=false

            if let scene = GameScene.unarchiveFromFile(environment_Prefix!+"GameScene") as? GameScene {
                // Configure the view.
                let skView = self.view as SKView!
                //skView.showsFPS = true
                //skView.showsNodeCount = true

                /* Sprite Kit applies additional optimizations to improve rendering performance */
                skView.ignoresSiblingOrder = true

                /* Set the scale mode to scale to fit the window */
                scene.scaleMode = .Fill

                skView.presentScene(scene, transition: SKTransition.flipVerticalWithDuration(2.0))

            }
        }
    })

由于

1 个答案:

答案 0 :(得分:3)

最后,我找到了有效的解决方案。我必须像这样实现GKLocalPlayerListener并在委托函数中调用邀请匹配。

   func player(player: GKPlayer!, didAcceptInvite invite: GKInvite!) {

    GKMatchmaker.sharedMatchmaker().matchForInvite (invite, {(InvitedMatch, error) in

        if InvitedMatch != nil {
            myMatch=InvitedMatch

            LocalGame=false

            if let scene = GameScene.unarchiveFromFile(environment_Prefix!+"GameScene") as? GameScene {
                // Configure the view.
                let skView = self.view as SKView!
                //skView.showsFPS = true
                //skView.showsNodeCount = true

                /* Sprite Kit applies additional optimizations to improve rendering performance */
                skView.ignoresSiblingOrder = true

                /* Set the scale mode to scale to fit the window */
                scene.scaleMode = .Fill

                skView.presentScene(scene, transition: SKTransition.flipVerticalWithDuration(2.0))

            }
        }
    })
}

要获得调用的播放器函数,我必须在本地播放器验证的块中注册侦听器,如下所示:

localPlayer.registerListener(self)

现在游戏邀请非常有效。