GameCenter: endTurnWithNextParticipants not advancing

一世执手 提交于 2019-12-20 06:26:56

问题


In the sandbox environment, I'm having trouble advancing a turnbased match to the next player.

Initial conditions:

  • Player A and Player B on Device A and Device B, respectively.
  • Both logged into the sandbox
  • Both players can see each other's GC status message
  • Player A creates a match and invites player B
  • Player A ends the turn

In my "end turn" function I do the following:

    NSLog(@"size = %ld", updatedMatchData.length);

    //move the current player to the bottom of the list
    NSMutableArray *nextPlayers = (NSMutableArray *)theMatch.participants;
    NSLog(@"%@", [nextPlayers description]);

    GKTurnBasedParticipant *firstGuy = nextPlayers[0];
    [nextPlayers removeObjectAtIndex:0];
    [nextPlayers addObject:firstGuy];

    NSLog(@"------");
    NSLog(@"%@", [nextPlayers description]);

    //send the match to the servers
    //"theMatch" was recorded in turnBasedMatchmakerViewController:didFindMatch

    [theMatch endTurnWithNextParticipants:nextPlayers
                              turnTimeout:GKTurnTimeoutDefault
                                matchData:updatedMatchData
                        completionHandler:^(NSError *error)
    {
        if (error)
        {
            NSLog(@"WTF?");
        }
    }];

That produces the following log output:

size = 26926
(
"<GKTurnBasedParticipant 0x174018630 - playerID:G:1084583147 (local player) status:Active matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>",
"<GKTurnBasedParticipant 0x174018ba0 - playerID:G:12962188 status:Invited matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>"
)
------
(
"<GKTurnBasedParticipant 0x174018ba0 - playerID:G:12962188 status:Invited matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>",
"<GKTurnBasedParticipant 0x174018630 - playerID:G:1084583147 (local player) status:Active matchOutcome:None lastTurnDate:(null) timeoutDate:(null)>"
)

However, player B does not receive an invite or a turn. Player B's game center app shows no active games or turns. Player A's game center continues to show that he still has a turn pending. Each time I restart and re-execute the test, Player A racks up yet another pending turn.

Player A fires player:receivedTurnEventForMatch:didBecomeActive right after I end the turn, but didBecomeActive is set to NO.

So then I changed the timeout to 30 seconds. 30 seconds after playerA ends the turn, playerA fires didBecomeActive (no). PlayerB finally receives an invite prompt. Player B fires didBecomeActive, with a value of YES.

Why does my turn not advance immediately to player B after player A ends the turn? Why does player A seem to have another turn (which then times out and passes over to player B)?


回答1:


Finally solved this. Do not attempt to edit the match object. Don't directly edit the matchData, or any other component of the match. Create a copy, do whatever you need to do to the copy and resubmit the copy.

My attempt to sort the players produced all sorts of erratic results until I created a completely separate participants array and sorted that. Then it worked as advertised.



来源:https://stackoverflow.com/questions/28522794/gamecenter-endturnwithnextparticipants-not-advancing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!