GameCenter邀请处理程序 [英] GameCenter Invitation Handler

查看:128
本文介绍了GameCenter邀请处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试实现多人游戏.使用游戏中心-发送和接收数据中的示例.

trying to implement a multiplayer. Using the sample from Game Center - Sending and receiving data.

一切似乎都还可以,但是在

Everything seems okay, but in apple documentation there is also said about invitation handler.

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
   // Insert application-specific code here to clean up any games in progress.
   if (acceptedInvite) {
        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    } else if (playersToInvite) {
        GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
        request.minPlayers = 2;
        request.maxPlayers = 4;
        request.playersToInvite = playersToInvite;

        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
        mmvc.matchmakerDelegate = self;
        [self presentModalViewController:mmvc animated:YES];
    }
};

问题很简单:我不知道将代码添加到何处.

The problem is quite simple: I do not know where to add this code.

推荐答案

文档中所述

您的应用程序应设置 邀请处理者最早 在您的应用程序之后 发射一个合适的地方 处理程序在完成块中 您提供的是在 本地播放器已通过身份验证.

Your application should set the invitation handler as early as possible after your application is launched; an appropriate place to set the handler is in the completion block you provided that executes after the local player is authenticated.

在代码中的某些地方,您应该已经使用类似这样的方式对本地播放器进行了身份验证

Somewhere in your code, you should have authenticated the local player with something like this

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    if (error == nil) {
        // Insert your piece of code here
    } else {
        // Handle the error
    }
}];

希望有帮助

这篇关于GameCenter邀请处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆