gpt4 book ai didi

ios - 如何从 Game Center 获取特定排行榜和时间范围的用户时间和排名?

转载 作者:可可西里 更新时间:2023-11-01 05:44:50 24 4
gpt4 key购买 nike

就 Apple 的游戏中心 api 而言,我将如何请求和取回本地用户时间以及特定排行榜和时间范围的排名?

  • 对于排行榜 X(即指定排行榜 - 例如 Level12_BestTime),对于给定的时间范围
  • 返回当前本地玩家:a) 时间 例如12.3秒b)排名(与 friend )例如12号c)排名(所有玩家)例如123

最佳答案

复制自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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com