Game Center Friend List

后端 未结 2 1762
清酒与你
清酒与你 2021-01-21 18:38

All

I made a game for the Apple iOS. Now I would like to show my friend list in Apple\'s Game Center.

How can I show the Game Center friend list of a logged in p

相关标签:
2条回答
  • 2021-01-21 18:55

    To show your Game center friends in your app you can use the below code given.

         -(void) retrieveFriends
       {
              GKLocalPlayer *lp = [GKLocalPlayer localPlayer]; 
              if (lp.authenticated)   
             { 
                 [lp loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error)
                 {
                     if (friends != nil)
                     {
                          [self loadPlayerData: friends];
                     }
    
                 }];
    
             }
    
        }
    
    
    
           -(void) loadPlayerData: (NSArray *) identifiers
            {
                 [GKPlayer loadPlayersForIdentifiers:identifiers withCompletionHandler:^(NSArray *players, NSError *error) 
               {
    
                  if (error != nil) 
                    {
                      // Handle the error.
                    } 
                 if (players != nil) 
                   {
              // Process the array of GKPlayer objects.
                   } 
               }];
    
              }
    

    For more reference you can use the Apple Game KIT guide. below is the link to it

    http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Introduction/Introduction.html

    Hope it helps..

    0 讨论(0)
  • 2021-01-21 19:10

    For a single Block:

    -(void)loadPlayerData:(void (^)(NSArray * playerObjects))complete
    {
        GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
        if (lp.authenticated)
        {
            [lp loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error)
             {
                 if (friends != nil)
                 {
                     [GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error)
                      {
    
                          if (error != nil)
                          {
    //                            return @[error];
                              // Handle the error.
                          }
                          else
                          {
                              complete (players);
    
                          }
                      }];
                 }
             }];
        }
    }
    
    0 讨论(0)
提交回复
热议问题