Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

24. GameKit > Managing Match State

Managing Match State

After establishing a match, it is the match delegate’s role to manage changes in the state of the match. The two primary fail states include a failed match (connection to Game Center) and a failed player connection (connection from Game Center to another player). For a failed match, you’ll want to alert the user, clean up your ongoing gameplay and revert to a pre-match “ready to play” state, as is shown in the following method:

- (void)match:(GKMatch *) aMatch didFailWithError:(NSError *)error
{
    NSLog(@"Match failed: %@",
        playerID, error.localizedFailureReason);
    [self cleanupGUI];

    // Alert the user. I include the error here because it can
    // provide useful context. You may choose otherwise.
    UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle:@"Lost Game Center connection"
        message:error.localizedFailureReason
        delegate:nil cancelButtonTitle:nil
        otherButtonTitles:@"Okay", nil];
    [alert show];
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial