如何在Swift(iOS)中从特定的Gamecenter排行榜中获取前10个得分?

我想从Leaderbaord中获取前10名得分和玩家,并在游戏中建立自定义的“名人堂”。
如何从Leaderbaord获取数据?

最佳答案

同时我找到了答案:

    let leaderBoardRequest = GKLeaderboard()
    leaderBoardRequest.identifier = kGcIdHighScore // my GC Leaderboard ID
    leaderBoardRequest.playerScope = GKLeaderboardPlayerScope.Global
    leaderBoardRequest.timeScope = GKLeaderboardTimeScope.AllTime
    leaderBoardRequest.range = NSMakeRange(1,10) // top 10

    leaderBoardRequest.loadScoresWithCompletionHandler
        { (scores, error) -> Void in
            if (error != nil)
                {
                    print("Error: \(error!.localizedDescription)")
                } else if (scores != nil)
                  {

                  print("got top \(scores?.count) scores"  )

                    var ii = 0
                    while (ii < scores?.count)
                    {
                        NSLog("%i ....... %@ %i %i", Int(ii+1), scores![ii].player.alias! , scores![ii].rank , scores![ii].value )
                        ii = ii + 1
                    }

                  }
        } // end leaderBoardRequest.loadScoresWithCompletionHandler

关于ios - 如何通过Swift(iOS)从特定的Gamecenter排行榜中获取前10个得分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33612915/

10-10 21:02