我想让我的游戏玩家参加一场特定的比赛。例如,PlayerA通过findMatchForRequest启动GKTurnBasedMatch。然后他想让他的朋友加入,但他不希望他的朋友在游戏中心寻找他,PlayerA想把matchID发送到PlayerB (比如说,通过社交媒体,或者其他什么).我的目标实际上是让玩家使用自定义的网址模式发送游戏链接给朋友,例如,mygame://join/**matchID**)。
从这里,PlayerB显然可以用GKTurnBasedMatch loadMatchWithID加载比赛.但他怎么能明确要求加入它呢?
[GKTurnBasedMatch loadMatchWithID:matchID withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) {
if(error || !match) {
[[AMAlertManager sharedManager] showError:i18n(@"errors.invalidInvite")];
}
else {
// Now what?
}
}];发布于 2013-09-13 15:13:34
最后我弄明白了,这很简单。诀窍是,一旦加载了GKTurnBasedMatch,您只需要查看找到的比赛参与者(这些是游戏中的参与者),然后从他们创建一个玩家ID数组。在执行.playersToInvite时,可以将此数组用作findMatchForRequest属性。
实际上,您可以将这个数组传递给handleInviteFromGameCenter委托方法,以便为游戏中心邀请重用现有代码。
此函数将允许播放器加入特定的matchID。
- (void)handleInviteToMatchID:(NSString*)matchID {
[GKTurnBasedMatch loadMatchWithID:matchID withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) {
if(error || !match) {
[[AMAlertManager sharedManager] showError:i18n(@"errors.invite.invalid")];
}
else if(match.status != GKTurnBasedMatchStatusMatching) {
[[AMAlertManager sharedManager] showError:i18n(@"errors.invite.notMatching")];
}
else {
NSMutableArray *playersToInvite = [NSMutableArray array];
for(GKTurnBasedParticipant *player in match.participants) {
if(player.playerID) {
[playersToInvite addObject:player.playerID];
}
}
[self handleInviteFromGameCenter:playersToInvite];
}
}];
}https://stackoverflow.com/questions/18772576
复制相似问题