gpt4 book ai didi

ios6 - GKMatchRequest 邀请未显示在其他设备中

转载 作者:行者123 更新时间:2023-12-01 01:05:44 26 4
gpt4 key购买 nike

感谢 iOS 6 中 GameKit API 的更新,我终于能够以它应有的方式实现我的回合制棋盘游戏,完成回合超时和更好的编程创建匹配。但是,我遇到了一个我似乎无法解决的问题。我的愿望是让 Game Center 运行时对最终用户完全不可见,以便一切都可以编程并使用我自己的自定义界面。因此,我使用自己的自定义表格 View 来显示匹配项,而不是默认的 GKTurnBasedMatchmakerViewController。现在,我可以使用 -loadMatchesWithCompletionHandler: 方法显示打开的匹配项。我还使用自定义屏幕来创建匹配,直接创建自动匹配(不是问题)和加载 localPlayer 的 Game Center 好友以进行邀请的表 View 。由于现在可以用 playerID 填充 playerToInvite 属性,这在 iOS 6 中是可能的。

我的主要问题是处理接收方的邀请。我用以下代码发送邀请

-(void)invitarAmigoMio:(NSArray*)losAmigos
{

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.defaultNumberOfPlayers=2;
request.playersToInvite = losAmigos;
request.inviteMessage = @"Your Custom Invitation Message Here";



request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse
response)
{

if (response==GKInviteeResponseAccepted)
{
NSLog(@"INVITACION ACEPTADA");
}
else
{
NSLog(@"INVITACION RECHAZADA");

}
};

}

我有一个处理通知的代表。以下代码在用户通过身份验证时启动
-(void)registroNotificaciones
{
NSLog(@"registroNotificaciones");

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite* acceptedInvite, NSArray *playersToInvite)
{
if(acceptedInvite != nil)
{
// Get a match for the invite we obtained...
[[GKMatchmaker sharedMatchmaker] matchForInvite:acceptedInvite completionHandler:^(GKMatch *match, NSError *error)
{
if(match != nil)
{
NSLog(@"match != nil: ");

}
else if(error != nil)
{
NSLog(@"ERROR: From matchForInvite: %@", [error description]);
}
else
{
NSLog(@"ERROR: Unexpected return from matchForInvite...");
}
}];
}
};
NSLog(@"FIN registroNotificaciones");

}

为什么没有发送通知?或者没有收到通知?还有其他方法可以发送通知邀请玩游戏吗?
我查了一下,我的 Game Center 沙盒帐户允许邀请,但我不知道发生了什么

最佳答案

您几乎完成了创建邀请所需的所有工作;你只需要用这个代码发送它:

[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch* match, NSError *error) {
if (error)
{
//Invite has not been sent
}
else if (match != nil)
{
//whatever you want to do when the receiver accepts the invite
}
}];

关于ios6 - GKMatchRequest 邀请未显示在其他设备中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16266089/

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