我想让我的游戏玩家加入特定的比赛。例如, PlayerA 通过GKTurnBasedMatch
启动findMatchForRequest
。然后他希望他的朋友加入,但不是希望他的朋友在游戏中心搜索他, PlayerA 想要将matchID
发送到 PlayerB (比如说,通过社交媒体或其他......我的目标实际上是让玩家使用自定义URL架构向朋友发送游戏链接,例如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?
}
}];
答案 0 :(得分:1)
我最终想出来了,这很简单。诀窍在于,一旦你加载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];
}
}];
}