カスタム 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];
}
}];
}