iphone - iOS GameCenter Matchmaker not working -


i’m trying make custom matchmakingview using matchmaker. code below used find match.

when run on 2 different devices different game center accounts, both match none connect match. stuck in while loop in infinity , never out. have missed something, need call connect match?

- (void) findmatch{ gkmatchrequest *request = [[gkmatchrequest alloc] init]; request.minplayers = 2; request.maxplayers = 2; request.playerstoinvite = nil; nslog(@"start searching!");  [matchmaker findmatchforrequest:request                withcompletionhandler:^(gkmatch *match, nserror *error)  {      if (error) {          // print error          nslog(@"%@", error.localizeddescription);      }      else if (match != nil)      {          curmatch = match;          curmatch.delegate = self;            nslog(@"expected: %i", match.expectedplayercount);           while (match.expectedplayercount != 0){              nslog(@"players: %i", curmatch.playerids.count);          }          nslog(@"start match!");      }  }]; 

you should not using while loop wait expectedplayercount reach 0, instead implement gkmatchdelegate method:

- (void)match:(gkmatch *)match player:(nsstring *)playerid didchangestate:(gkplayerconnectionstate)state {     if (!self.matchstarted && match.expectedplayercount == 0) {         self.matchstarted = yes;         //now should start match.     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -