我即将完成我的第一个使用(并需要) Game Center的应用程序。我不是在追求成就,而是一个高分系统。我已经把所有东西都插上了,我的应用程序在iTunesConnect中注册,并启用了游戏中心,当我记录一个高分时,它会出现在应该出现的列表中。
唯一不起作用的是“排名”。在[GKScore reportScoreWithCompletionHandler:]的完成块中,我的GKScore对象的rank属性始终为0,即使用户获得了新的高分。
例如,在我的应用程序中,当我运行:
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"1"];
scoreReporter.value = 2200003; // test value
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(@"An error occured reporting the Game Center score: %@", error);
}
NSLog(@"Score: %@", scoreReporter);
NSLog(@"Score: %d", scoreReporter.rank);
}];出现...no错误,输出为:
Score: <GKScore: 0x361a3c0><0x361a3c0> player=G:1127411264 rank=0 date=2012-02-04 22:19:52 +0000 value=2200002 formattedValue=(null) context=(null)
Score: 0是不是我在iTunesConnect中遗漏了什么?当我离开沙箱后,rank会开始工作吗?任何指向正确方向的指针都将不胜感激。
发布于 2012-02-14 20:49:50
您的代码中没有错误。如果只创建GKScore对象,则rank的值始终为0。仅对从Game Center收到的score对象有效。请阅读此文档:https://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKScore_Ref/Reference/Reference.html
发布于 2012-02-20 17:56:09
laxcat,您不能立即获取刚刚加分的排名,但经过一段时间后,您可以请求获取用户排名:
GKLeaderboard *lb = [[[GKLeaderboard alloc] init] autorelease];
lb.category = @"YOURLeaderBoardID";
lb. timeScope = GKLeaderboardTimeScopeToday;
[lb loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error)
{
GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
for (GKScore* score in scores)
{
if ([score.playerID sEqualToString:lp.playerID])
{
NSLog(@"rank = %d", score.rank);
}
}
}];请试一试,让我知道它是否适合你。
发布于 2012-07-11 21:00:20
您需要将整数转换为int64_t。在Objective-C术语中,这是一个LongLong。您可以对此进行更改:
GKScore *myScore = [[GKScore alloc]initWithCategory:@"1"];
myScore.value = [[NSNumber numberWithInt:score] longLongValue]; //score should be of type inthttps://stackoverflow.com/questions/9145269
复制相似问题