swift - 如何在swift中接受Game Center邀请

标签 swift game-center

我在快速接受邀请时遇到了一些麻烦。

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

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))

            }
        }
    })

谢谢

最佳答案

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

   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))

            }
        }
    })
}

要调用播放器函数,我必须像这样在本地播放器身份验证 block 中注册监听器:

localPlayer.registerListener(self)

现在游戏邀请完美运行。

关于swift - 如何在swift中接受Game Center邀请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27068111/

相关文章:

swift - 检索最佳成绩 Game Center Swift

request - GKTurnBasedMatch 识别玩家组

ios - 使用 Swift 设置 Game Center

ios - 离开屏幕时,Tableview 部分标题无法正确转换

swift - swift 3 中的初始化方法

iphone - Gamecenter 显示名称在 Release模式下添加了引号

objective-c - GameKit 与 GKMatchSendDataReliable 的通信是否可靠?

swift - 如何在 tvOS 中将 UITableViewCell 中的 UICollectionViewCell 聚焦?

ios - 接收器 ... 没有标识符错误的 segue

swift 。将 UIImagePicker 的委托(delegate)作为参数传递