正如苹果指南所说;我已经在我的游戏中心课程中实施了GKLocalPlayerListener
协议,并在他的身份验证后立即将本地播放器添加为听众:
func authenticationChanged() {
if (GKLocalPlayer.localPlayer().authenticated && !self.userAutenticated) {
println("Authentication changed: player authenticated.")
userAutenticated = true
GKLocalPlayer.localPlayer().unregisterAllListeners()
GKLocalPlayer.localPlayer().registerListener(self)
} else if (GKLocalPlayer.localPlayer().authenticated && self.userAutenticated) {
println("Authentication changed: player not authenticated.")
userAutenticated = false
}
}
协议实施:
// MARK: - GKLocalPlayerListener
func player(player: GKPlayer!, didAcceptInvite invite: GKInvite!) {
println("Did accept invite")
}
func player(player: GKPlayer!, didRequestMatchWithRecipients recipientPlayers: [AnyObject]!) {
println("Did request matchmaking")
}
当我尝试邀请朋友时,这两种方法都没有,我也没有收到任何类型的通知。 我试图在发布模式下测试游戏,但我得到了相同的结果。 我必须说正常的配对工作正常,我能够找到没有任何问题的玩家。
修改
如果我从2台设备测试它,则会收到通知,但如果我点击通知,该应用程序将会打开,并且不会调用任何代表。如果我关闭应用并再次重新启动,则会调用GKLocalPlayerListener
。
出了什么问题?
答案 0 :(得分:1)
我认为,当你说“正常的配对工作”时,你提出了一个matchmakerviewcontroller:
-(IBAction)setupMatch:(id)sender{
GKMatchmakerViewController *matchViewController = [[GKMatchmakerViewController alloc] initWithMatchRequest:matchRequest];
matchViewController.matchmakerDelegate = self;
[self presentViewController:matchViewController animated:YES completion:nil];}
然后当在matchmakerviewcontroller中找到玩家时,将调用didFindMatch:
-(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{
//Called when GameCenter completes the matchmaking process
match.delegate = (id)self; //etc. lots of your own code here.
didAcceptinvite仅在接受邀请后才会在邀请的收件人的设备上调用:
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite{
//Called on the accepting device when the invitation is accepted
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:invite];
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
向您的朋友展示matchmakerviewcontroller。他们没有什么可做的,vc建立联系然后解散自己。发送设备上的vc同时解散。
然后在两个设备上调用didFindMatch,然后离开。
我不相信didrequestMatchWithRecipients被调用,当didFindMatch和didAcceptInvite处理游戏开始两端时,它似乎是多余的。
我发现WWDC 2012的这段视频非常有用:WWDC 2012 Christy Warren