简体   繁体   中英

iOS: Retrieve Game Center friends who are online

I can retrieve all Game Center friends with this code...

GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
    if (lp.authenticated)
    {
        [lp loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error)
         {
             NSLog(@"MY FRIENDS: %@",friends);
             if (friends != nil)
             {
                 [GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error)
                  {

                      if (error != nil)
                      {
                          // Handle the error.
                          NSLog(@"PLAYERLIST ERROR: %@",[error localizedDescription]);
                      }
                      if (players != nil)
                      {
                          // Process the array of GKPlayer objects.
                          NSLog(@"PLAYERS: %@",players);
                      }
                  }];
             }

         }];

    }

... however, is there a way to retrieve only the friends with GameKit who are online ?

It does not look like you are able to. Since GKPlayer does not offer any way to view if a player is online or not.

Also since technically once a person logs on to Game Center they are "Online" till they log off. Meaning they could be online for days while using their phone. When they are logged on if you send them an invite they will get the trumpet noise.

http://developer.apple.com/library/IOS/#documentation/GameKit/Reference/GKPlayer_Ref/Reference/Reference.html#//apple_ref/doc/uid/TP40009599

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM