我试图在基于回合的游戏中实现一个事件监听器,以便玩家可以在他的回合处于活动状态或被朋友邀请时接收到事件监听器。 GKTurnBasedEventHandler 在 IOS 7 中已弃用,我在文档中读到我应该使用 GKLocalPlayerListener;但这就是它的延伸。有人用过吗,因为没有任何信息。
这是我之前尝试过的,但行不通。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error)
{
if (localPlayer.isAuthenticated)
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer registerListener:self];
}
}];
return YES;
}
-(void)handleInviteFromGameCenter:(NSArray *)playersToInvite
{
NSLog(@"test");
}
- (void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive
{
NSLog(@"test");
}
这是我用来注册 GKLocalPlayerListener 的一些代码
__weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
if (viewController) {
[authenticateFromViewController presentViewController:viewController animated:YES completion:^{
[localPlayer registerListener:self];
NSLog(@"Authenticated. Registering Turn Based Events listener");
}];
} else if (localPlayer.authenticated) {
[localPlayer registerListener:self];
NSLog(@"User Already Authenticated. Registering Turn Based Events listener");
} else {
NSLog(@"Unable to Authenticate with Game Center: %@", [error localizedDescription]);
}
};
该文档指出,您应该只注册一次 GKLocalPlayerEventListener,这样您就可以通过检查您是否已经注册来改进此代码。
注意authenticateWithCompletionHandler
在 iOS 6 中已弃用,他们建议像我上面那样设置authenticateHandler 属性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)