1

カスタム UI を使用してリアルタイム マルチプレイヤー ゲームを実装しようとしています (no 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];
        }
    }];
}
4

1 に答える 1

1

理解した!- (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler両方のプレーヤーが同じ試合データを持つように、招待ハンドラー を呼び出す必要がありました。

于 2013-02-01T01:35:10.157 に答える