Disconnections

The last step that we need to take when working with multiplayer support is to add in logic to handle disconnections and other failures that are unrecoverable. Luckily for us, Apple's APIs handle most of the legwork. We do, however, want to add a more universal call to our GameCenterManager class to make things easier for us.

- (void)disconnect; {         if ([self.matchOrSession isKindOfClass: [GKSession class]])         {                         [self.matchOrSession disconnectFromAllPeers];         }         else if ([self.matchOrSession isKindOfClass: [GKMatch class]])         {                         [self.matchOrSession disconnect];         } }

This method should be called whenever you wish to end a multiplayer game. It ...

Get Beginning iOS Game Center and Game Kit: For iPhone, iPad, and iPod touch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.