Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering iOS Game Development

You're reading from   Mastering iOS Game Development Mastering iOS Game Development

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher Packt
ISBN-13 9781783554355
Length 228 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Peter Ahlgren Peter Ahlgren
Author Profile Icon Peter Ahlgren
Peter Ahlgren
Miguel DeQuadros Miguel DeQuadros
Author Profile Icon Miguel DeQuadros
Miguel DeQuadros
Arrow right icon
View More author details
Toc

Game Center integration


Matchmaker, matchmaker find me a match! Now's the time to start finding our friends!

Let's pop over to our MultiplayerHelper.h file so that we can add in a new dictionary to store the players we find. Just after the @interface line, add in the following declaration:

@property(nonatomic, strong) NSMutableDictionary *playersDict;

This dictionary allows Game Kit to easily look up player data.

Now, we will go over to our MultiplayerHelper.m file and make a few new changes. First, we will add a new method just after we authenticate our local player:

- (void)lookupPlayers {
    
    NSLog(@"Looking up %lu players...", (unsigned long)_match.playerIDs.count);
    
    [GKPlayer loadPlayersForIdentifiers:_match.playerIDs withCompletionHandler:^(NSArray *players, NSError *error) {
        
        if (error != nil) {
            NSLog(@"Error retrieving player info: %@", error.localizedDescription);
            _matchStarted = NO;
            [_delegate matchEnded];
        } else...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime