2014-11-21 43 views
0

我有一些麻煩讓快速接受邀請。如何快速接受遊戲中心邀請

有人可以幫助我正確的編碼?這裏是我的

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

最後我想通了其運作的解決方案。我必須像這樣實現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) 

現在,遊戲邀請作品完美。