gpt4 book ai didi

iphone - iOS Gamecenter 程序化配对

转载 作者:行者123 更新时间:2023-11-29 13:20:26 25 4
gpt4 key购买 nike

我正在尝试使用自定义 UI(无 GKMatchMakerViewController)实现实时多人游戏。我正在使用 startBrowsingForNearbyPlayersWithReachableHandler:
^(NSString *playerID, BOOL reachable)
找到本地玩家,然后用GKMatchmaker 单例发起匹配请求(我已经发起了)。

这是我遇到麻烦的地方。当我发送一个请求时,完成处理程序几乎立即触发,没有错误,并且它返回的比赛的预期玩家数为零。而对方,肯定没有回应这个请求。

相关代码:

- (void) findMatch
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = NUM_PLAYERS_PER_MATCH; //2
request.maxPlayers = NUM_PLAYERS_PER_MATCH; //2
if (nil != self.playersToInvite)
{
// we always successfully get in this if-statement
request.playersToInvite = self.playersToInvite;
request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse
response)
{
[self.delegate updateUIForPlayer: playerID accepted: (response ==
GKInviteeResponseAccepted)];
};
}
request.inviteMessage = @"Let's Play!";

[self.matchmaker findMatchForRequest:request
withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error) {
// Print the error
NSLog(@"%@", error.localizedDescription);
}
else if (match != nil)
{
self.currentMatch = match;
self.currentMatch.delegate = self;

// All players are connected
if (match.expectedPlayerCount == 0)
{
// start match
[self startMatch];
}
[self stopLookingForPlayers];
}
}];
}

最佳答案

想通了!我需要在我的邀请处理程序中调用 - (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler 这样两个玩家都有相同的匹配数据。

关于iphone - iOS Gamecenter 程序化配对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14492171/

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