2013-01-24 2 views
1

맞춤형 UI (아니 GKMatchMakerViewController)를 사용하여 실시간 멀티 플레이어 게임을 구현하려고합니다. startBrowsingForNearbyPlayersWithReachableHandler: ^(NSString *playerID, BOOL reachable)을 사용하여 로컬 플레이어를 찾은 다음 GKMatchmaker 싱글 톤 (이미 시작한 항목)으로 일치 요청을 시작합니다.iOS 게임 센터 프로그램 매치 메이킹

여기 내가 문제가있는 곳입니다. 요청을 보내면 완료 처리기가 오류없이 거의 즉시 시작되고 반환되는 일치 항목의 예상 플레이어 수는 0입니다. 한편, 다른 플레이어는 확실히 요청에 응답하지 않았습니다.

관련 코드 :

- (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]; 
     } 
    }]; 
} 

답변

1

그것을 알아 냈어! 초대장 처리기에서 - (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler으로 전화하여 두 플레이어가 동일한 경기 데이터를 갖도록해야했습니다.