2015-08-29 63 views
1

我正在嘗試開發一個簡單的多人遊戲。按照Apple文檔中的說明,我正在實施邀請處理程序「matchforinvite」,以便我可以接受來自其他玩家的邀請。 https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKMatchmaker_Ref/#//apple_ref/occ/instm/GKMatchmaker/matchForInvite:completionHandler:如何編寫適用於iOS 9的Invitehandler Xcode 7 beta 6

我通過以下功能

func setUpInviteHandler() { 

    GKMatchmaker.sharedMatchmaker().matchForInvite(invite: GKInvite, completionHandler: { match, error -> Void in 
     if invite.playerAttributes != 0 { 
      print(invite.playerAttributes) 
     } 
    }) 

} 

這樣做然而,無論我如何改變它總是有距離的Xcode錯誤。我怎麼修復它?

這裏的問題(我猜)是GKInvite對象直到有邀請纔會存在。然而,當你做這樣的功能時,GKInvite必須被初始化才能被調用。你怎麼能初始化一個運行時對象?最糟糕的是我無法做到!(GKInvite)或GKInvite ==由於類的類型而無法檢查。誰能幫忙?

+0

好下,你很不是味兒。你**有**擁有一個有效的GKInvite在你想調用'matchForInvite'的地方。您應該閱讀關於該主題的一些教程。一般情況下,'GKInvite'是這個類型,你需要的是一個你通常從匹配過程中的一些其他回調方法獲得的實例。 – luk2302

+0

感謝您的指導。我會再試一次。謝謝 – chihoxtra

回答

0

目前我把matchforinvite處理事情的協議功能

func player(player: GKPlayer, didAcceptInvite invite: GKInvite) { 
    self.debug("did received and accepted an invite" + String(player.playerID)) 

    GKMatchmaker.sharedMatchmaker().matchForInvite(invite, completionHandler: { match, error -> Void in 
     self.debug("Invite received") 





    }) 


} 

的錯誤消失,但仍邀請無法獲得直通