iOS版的GameCenter编程对接会(iOS Gamecenter Programmatic M

2019-10-17 15:16发布

我试图实现实时多人游戏的自定义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];
        }
    }];
}

Answer 1:

弄清楚了! 我需要调用- (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler在我的邀请处理程序,以便双方球员有相同的比赛数据。



文章来源: iOS Gamecenter Programmatic Matchmaking