2017-02-07 2 views
1

여러 번 여기에서 다뤘던 아주 오래된 문제에 직면했습니다. 이 문제를 많은 시간 동안 이야기했지만, 나는 받아 들일만한 해결책을 찾지 못했고 그래서 나는 다시 한번 문제를 제기하기로 결정했다.게임 센터 샌드 박스 문제

그래서 문제가 있습니다. 턴 기반 매치를 테스트하려고합니다. 나는 이것을 위해 두 개의 실제 장치를 사용한다. 나는 첫 번째 장치를 켜고 일치 데이터를 오류없이 업데이트합니다 (나는 확실히 알고 있습니다). 그러나 때로는 두 번째 장치가 어떤 알림도받지 못하고 첫 번째 장치가 여전히 켜져있는 것으로 보입니다. 때로는 예상대로 작동합니다.

즉, player(_:receivedTurnEventFor:didBecomeActive)라는 메서드가 가끔 호출되지 않습니다. 하지만 두 번째 장치에서 응용 프로그램을 닫으면 다시 열어 기존 일치 항목에 모두 연결하면됩니다. 이것은 게임 센터 샌드 박스 문제로 잘 알려져 있지만, 앱을 테스트하는 동안 나에게 미친 짓이됩니다. 해결 방법에 대해 아는 사람이 있습니까? 아니면이 이상한 샌드 박스 동작으로 앱을 실행하고 테스트하는 것이 가장 좋은 방법일까요?

업데이트. 썽크 (Thunk)가 제안한 방법이 해결책입니다. 스위프트에서 다시 작성하고 내 게임 논리와 일치하도록 수정했습니다. 첫째, 나는 endTurn(withNextParticipants:turnTimeOut:match:completionHan‌​dler:) 완료 핸들러에서 전역 변수 var gcBugTimer: Timer

정의 : 플레이어가 차례로 새로운 경기와 다른 플레이어 joying 경우도 위의

let interval = 3.0 
self.gcBugTimer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(self.isMatchActive), userInfo: nil, repeats: true) 
self.gcBugTimer.tolerance = 1.0 

코드가 경우 호출해야합니다.

그런 다음 타이머 방법 :

func isMatchActive() { 
    // currentMatch - global variable contains information about current match 
    GKTurnBasedMatch.load(withID: currentMatch.matchID!) { (match, error) in 
    if match != nil { 
     let participant = match?.currentParticipant 
     let localPlayer = GKLocalPlayer.localPlayer() 
     if localPlayer.playerID == participant?.player?.playerID { 
     self.player(localPlayer, receivedTurnEventFor: match!, didBecomeActive: false) 
     } 
    } else { 
     print(error?.localizedDescription ?? "") 
    } 
    } 
} 

그리고 player(_:receivedTurnEventFor:didBecomeActive)의 맨 처음에 다음 코드를 추가합니다

if gcBugTimer != nil && gcBugTimer.isValid { 
    gcBugTimer.invalidate() 
} 
+0

, 당신은 회전에서 경기 데이터를 저장하거나 종료 언급하는 그냥 명확하게 전부 차례? 두 사람 모두 여러 번 알림을받지 못했습니다. – Thunk

+0

내 게임의 논리에 따르면, 턴 내에 데이터를 저장할 필요가 없습니다. 그래서 나는 단지'endTurn (withNextParticipants : turnTimeOut : match : completionHandler :)'를 호출함으로써 차례를 끝낸다. 그리고 또 하나. 때로는 예상대로 작동합니다. 두 번째 기기는 전송 직후에 차례를 수신하고 때로는 경기 데이터를 업데이트하기 위해 경기에 다시 참여해야합니다. –

답변

1

그 기다리는 동안 안정적으로 수동으로 상태를 다시 확인했다 일을 내가 찾은 유일한 해결책 내 차례 야. endTurnWithNextParticipants의 완료 처리기에서 일치 데이터를 지속적으로 다시로드하도록 타이머를 설정했습니다. localPlayer이 (가) 활성 선수가되었는지 확인합니다. 그렇다면 receivedTurnForEvent 자신을 호출, 그렇지 않으면 타이머를 반복했다. 그래서 같이 :

 float dTime = 60.0;  //messages sometimes fail in IOS8.4 
     if (SYSTEM_VERSION_EQUAL_TO(@"8.3")) 
     { 
      dTime = 5.0;  //messages always fail in IOS8.3 
     } 
     IOS8BugTimer = [NSTimer scheduledTimerWithTimeInterval:dTime 
                  target:gameKitHelper 
                  selector:@selector(isMatchActive:) 
                  userInfo:theMatch.matchID 
                  repeats:NO]; 

및 gameKitHelper에

: isMatchActive 다음 endTurnWithNextParticipants 완료 핸들러에서

-(void)isMatchActive:(NSTimer *)timer 
{ 

    NSString *matchID = (NSString *)timer.userInfo; 
    [GKTurnBasedMatch loadMatchWithID:matchID withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) 
    { 
     GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 
     GKTurnBasedParticipant *currentParticipant = match.currentParticipant; 

     if ([localPlayer.playerID isEqualToString:currentParticipant.player.playerID]) 
     { 
      //we have become active. Call the event handler like it's supposed to be called 
      [self player:localPlayer receivedTurnEventForMatch:match didBecomeActive:false]; 
     } 
     else 
     { 

      //we are still waiting to become active. Check back soon 
      float dTime = 60.0; 

      if (SYSTEM_VERSION_EQUAL_TO(@"8.3")) 
      { 
       dTime = 5.0; 
      } 

      gameController.IOS8BugTimer = [NSTimer scheduledTimerWithTimeInterval:dTime 
                     target:self 
                    selector:@selector(isMatchActive:) 
                    userInfo:matchID 
                     repeats:NO]; 
     } 
    }]; 

} 
+0

많은 조언에 감사드립니다. 다른 질문. 릴리스 후에도 내 코드가 제대로 작동합니까? 아니면 일반 GameCenter에서도 수동으로 상태를 다시 확인해야합니까? –

+0

Apple에 따르면 더 이상 별도의 샌드 박스가 없습니다. Apple이 설명서를 업데이트했다고 생각하지는 않지만이 링크는 원래 발표 내용을 설명하고 개발 코드를 동일한 제품 서버 (http : //news.softpedia)로 옮기는 데 대한 몇 가지 장단점을 제시합니다.co.kr/news/apple-removed-game-center-sandbox-migrates-test-servers-to-release-environment-493807.shtml을 참조하십시오. 필자가 보았던 것에서, 테스트 후에 릴리스 된 것과 동일한 동작을 기대해야합니다. – Thunk

+0

정말 작동합니다. 귀하의 코드에 따라 초기 질문을 업데이트했습니다. –