Game Center Friend List

穿精又带淫゛_ 提交于 2019-12-02 02:20:29

问题


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 player on an iPhone, possibly using the UIViewController (which manages the ViewControllers)?

Any help would be appreciated..

Thanks...


回答1:


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..




回答2:


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);

                      }
                  }];
             }
         }];
    }
}


来源:https://stackoverflow.com/questions/8336971/game-center-friend-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!