gpt4 book ai didi

iOS 7 : How to setup invitation handler for Game Center matchmaker

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:44 27 4
gpt4 key购买 nike

在 iOS 7 中处理来自其他玩家的邀请的正确方法是什么?

在我的 View 确实加载到我的 Root View Controller 上之后,我调用了游戏中心身份验证方法,之后我设置了一个邀请处理程序,如下所示:

[[GKLocalPlayer localPlayer] registerListener:self];

我的 View Controller 采用GKLocalPlayerListenerGKInviteEventListener 协议(protocol),顺便问一下,注册监听器AppDelegate 的最佳位置是什么?也许或者也许是我的自定义 Game Center 单例?

我添加了 GKInviteEventListener 中描述的方法

-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"Invite accepted!");
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:invite];
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];

}

但是,游戏中心的媒人类有这样的话题:Receiving Invitations From Other Players and method – matchForInvite:completionHandler:我不明白如何使用它。

那么,我必须使用什么以及如何使用?

最佳答案

我认为你做的事情是正确的。我以同样的方式做事,它对我有用。 -matchForInvite:completionHandler 在 iOS 7 中已被弃用,所以我没有对它做任何事情。

首先我设置了身份验证处理程序。这是在我的应用程序首次加载时调用的,您可以将其设置在任何您喜欢的位置,但最好尽快设置处理程序。

-(void)authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;

//Block is called each time GameKit automatically authenticates
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
[self setLastError:error];
if (viewController)
{
self.authenticationViewController = viewController;
[self disableGameCenter];
}
else if (blockLocalPlayer.isAuthenticated)
{
[self authenticatedPlayer:blockLocalPlayer];
}
else
{
[self disableGameCenter];
}
};
}

如果身份验证成功,则调用此方法:

-(void)authenticatedPlayer:(GKLocalPlayer*)localPlayer
{
self.isAuthenticated = YES;
[[NSNotificationCenter defaultCenter]postNotificationName:AUTHENTICATED_NOTIFICATION object:nil];
[[GKLocalPlayer localPlayer]registerListener:self];
}

然后我实现了两个监听方法:

(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
//.... insert some cleanup code here to manage view controllers etc before presenting the matchmakerviewcontroller.
[self presentMatchmakerViewControllerWithInvite:invite];
}


-(void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite
{
//......insert some cleanup code for managing view controllers
GKMatchRequest *match = [[GKMatchRequest alloc]init];
match.playersToInvite = playerIDsToInvite;

GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithMatchRequest:match];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}

关于iOS 7 : How to setup invitation handler for Game Center matchmaker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21166617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com