我在快速接受邀请时遇到了一些麻烦。
有人可以帮我正确编码吗?这是我的
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/