ios - Game Center : match delegate’s not called after finding a match -
i'm trying use game center : multi player
till now, players authenticating game center, can send/read scores, , acheivements. multiplayer features, tried both methods : - using game center interface find match. - find match programmatically.
for both ways have following issue: match delegate’s match:player:didchangestate: method not called. in apple docs, it's stated delegate called if 1 player connected or disconnected.
in case delegate never called. think i'm missing step. here after implementation of delegate (as specified in apple doc).
- (void)match:(gkmatch *)match player:(nsstring *)playerid didchangestate:(gkplayerconnectionstate)state { switch (state) { case gkplayerstateconnected: // handle new player connection. break; case gkplayerstatedisconnected: // player disconnected. break; } if (!self.matchstarted && match.expectedplayercount == 0) { self.matchstarted = yes; // handle initial match negotiation. } }
and code find match.
-(void) findprogrammaticmatch { gkmatchrequest *request = [[[gkmatchrequest alloc] init] autorelease]; request.minplayers = 2; request.maxplayers = 2; [[gkmatchmaker sharedmatchmaker] findmatchforrequest:request withcompletionhandler:^(gkmatch *foundmatch, nserror *error) { if (error) { // process error. statuslabel.text = @"match not found"; } else if (foundmatch != nil) { multiplayermatch = foundmatch; // use retaining property retain match. statuslabel.text = @"match found"; multiplayermatch.delegate = self; // start! // start match. // start game using match. [self startmatch]; } }]; }
thanks help.
it working along. difference that... when use invites event "didchangestate" doesn't called. you're connected without notice , can start receive data. never tried send/receive data because expecting event first, did send mistake 1 time, , worked.
- (void)matchmakerviewcontroller:(gkmatchmakerviewcontroller *)viewcontroller didfindmatch:(gkmatch *) match { //dismiss window [self dismissmodalviewcontrolleranimated:yes]; //retain match self.mymatch = match; //delegate mymatch.delegate = self; //flag matchstarted = true; //other stuff } - (void)match:(gkmatch *)match player:(nsstring *)playerid didchangestate:(gkplayerconnectionstate)state { //this code gets called on auto-match }
the above code works expected.
Comments
Post a Comment