作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
就 Apple 的游戏中心 api 而言,我将如何请求和取回本地用户时间以及特定排行榜和时间范围的排名?
最佳答案
复制自Game Center Programming Guide :
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal; // or GKLeaderboardPlayerScopeFriendsOnly
leaderboardRequest.timeScope = GKLeaderboardTimeScopeToday; // or GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime
leaderboardRequest.identifier = @"Combined.LandMaps" // Name of the leaderboard
leaderboardRequest.range = NSMakeRange(1,10); // How many results to get
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil)
{
// Handle the error.
}
if (scores != nil)
{
// Process the score information.
}
}];
}
获取特定用户的信息:
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] initWithPlayerIDs: match.playerIDs];
在这两种情况下,用户的分数都存储在 localPlayerScore 中,所有分数都存储在 scores 中。
然而,排名可能存在问题。您最多只能获得 100 分,因此如果排行榜非常大,它可能需要很多电话。 localPlayerScore 确实包含一个 rank 值,但这仅与当前的 scores 列表有关。基本上,您必须遍历整个排行榜才能找到用户的位置。
关于ios - 如何从 Game Center 获取特定排行榜和时间范围的用户时间和排名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19485611/
我是一名优秀的程序员,十分优秀!