ios - Some startBrowsingForNearbyPlayersWithReachableHandler questions -


i'm trying local matchmaking working in gamekit using [[gkmatchmaker sharedmatchmaker] startbrowsingfornearbyplayerswithreachablehandler:]. essentially, i'm trying implement interface-less local matches: long there's player in local vicinity, want connect , start match. importantly, only want local players: never want match automatically on internet.

i've enabled game center app in itunes connect , signed different sandbox account on every device i'm using test.

i've tried both matchmaking gkmatchmakerviewcontroller (after authenticating local player) , programmatic matchmaking startbrowsingfornearbyplayerswithreachablehandler:, running same code on iphone 4 , 4th gen ipod touch sitting next each other on desk. neither ever finds other; when using gkmatchmakerviewcontroller interface finding nearby players remains @

finding players...

spinner, , when using startbrowsingfornearbyplayerswithreachablehandler:, notification block never gets called.

here's current block of testing code:

-(void)connectlocal {     if( ![gklocalplayer localplayer].isauthenticated )     {         // authenticatelocalplayer calls connectlocal again after authentication complete         [ self authenticatelocalplayer ];         return;     }     [[gkmatchmaker sharedmatchmaker] startbrowsingfornearbyplayerswithreachablehandler:^(nsstring *playerid, bool reachable) {              nslog(@"reachability changed player %@", playerid );         } ]; } 

the docs little sparse & confusing on subject, when comes difference between local mulitplayer , matches on internet. instance, seems necessary authenticate local player , create match before finding players join match (creating kind of match starts match request). this little nugget seems suggest otherwise:

the standard user interface allows players discover other nearby players, when neither player connected game center directly.

additionally, in flow described in searching nearby players, match request isn't created until step 3, after finding players via notification block passed startbrowsingfornearbyplayerswithreachablehandler:. unfortunately, i've never got far.

so, questions:

1) right in thinking can call startbrowsingfornearbyplayerswithreachablehandler: before authenticating local player? gamekit doesn't throw error, i'm assuming it's ok. may rash assumption. whether authenticate or not doesn't seem make difference.

2) has implemented local auto-matching using [gkmatchmaker sharedmatchmaker] startbrowsingfornearbyplayerswithreachablehandler:? there example code anywhere illustrates complete flow, browsing players starting match, programmatically?

3) there seem conflicting reports on web on whether gamekit-enabled apps can tested in ios simulator. general consensus seems not, , it's better test on ios hardware. i've been using iphone 4 & 4th gen ipod touch. have tested local multiplayer, testing setup & methodology did use?

you need these things in order:

  1. authenticate local player
  2. install invite handler
  3. start browsing nearby players

authentication required - registers app game center , logs player in. in cases, won't need internet access this.

installing invitation handler required, , think step you're missing. lets app know when inbound invitation received. if don't this, device won't register being nearby.

only start browsing once you've done above two.

here's sample code going. call method after app launches:

- (void) authenticatelocalplayer {      static bool gcauthenticationcalled = no;     if (!gcauthenticationcalled) {         gklocalplayer *localplayer = [gklocalplayer localplayer];          void (^authenticationhandler)(uiviewcontroller*, nserror*) = ^(uiviewcontroller *viewcontroller, nserror *error) {             nslog(@"authenticating game center.");             gklocalplayer *mylocalplayer = [gklocalplayer localplayer];             if (viewcontroller != nil)             {                 nslog(@"not authenticated - storing view controller.");                 self.authenticationcontroller = viewcontroller;             }             else if ([mylocalplayer isauthenticated])             {                 nslog(@"player authenticated!");                  //ios8 - register listener                 [localplayer unregisteralllisteners];                 [localplayer registerlistener:self];                  [[gklocalplayer localplayer] loadfriendplayerswithcompletionhandler:^(nsarray *friendplayers, nserror *error) {                      //do friends                  }];                  //ios7 - install invitation handler                 [gkmatchmaker sharedmatchmaker].invitehandler = ^(gkinvite *acceptedinvite, nsarray *playerstoinvite) {                     // insert game-specific code here clean game in progress.                     if (acceptedinvite)                     {                         //this player accepted invitation.                         //if doing programmatic matchmaking, call gkmatchmaker's matchforinvite:completionhandler                          //to match invite.  otherwise need allocate gkmatchmakerviewcontroller                          //instance , present invite.                      }                     else if (playerstoinvite)                     {                         //your game launched gamecenter app host match.                     }                 };                  //now can browse.  note ios8 call.  ios7 call different.                 [[gkmatchmaker sharedmatchmaker] startbrowsingfornearbyplayerswithhandler:^(gkplayer *player, bool reachable) {                      nslog(@"player nearby: %@", player.playerid);                  }];                }             else             {                 //authentication failed.                 self.authenticationcontroller = nil;                 if (error) {                     nslog([error description], nil);                 }             }           };          localplayer.authenticatehandler = authenticationhandler;         gcauthenticationcalled = yes;     } } 

* important * if you're using ios8, don't install invitation handler. instead register object listening protocol gklocalplayerlistener, , implement these methods:

-player:didacceptinvite: -player:didrequestmatchwithrecipients: 

if don't implement these methods on ios8, won't work!

you link gkmatchmaker object calling after authenticating local player:

[localplayer registerlistener:self]; 

make sure object that's implementing protocol declared in .h file:

@interface myimplementingobject : nsobject <gkmatchdelegate, gklocalplayerlistener> 

if , still isn't working, make sure have bundle id set correctly in app (click app, click 'targets', make sure bundle identifier , version filled in), click 'capabilities' tab (xcode 6), , make sure game center on.

go member center , make sure app using bundle id has game center enabled provisioning profile. download , reapply provisioning profile if necessary.

make sure sandbox switch on in settings under gamecenter, , make sure 'allow invites' , 'nearby players' switches turned on.

finally, make sure go itunes connect , verify game center enabled app there well.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -