我正在为iOS 7创建一个游戏,并试图实现游戏中心排行榜。我让应用程序在我点击某个按钮时打开排行榜,但它显示“没有项目”。我现在不确定这是提交分数或检索排行榜的问题。提交分数似乎有问题,因为它在我的排行榜顶部显示了应用程序名称,但我找不到我的错误。我提交分数的代码:
-(void)reportScore:(NSInteger ) highScore
{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:@"flapjacks1" forPlayer:[GKLocalPlayer localPlayer].playerID];
scoreReporter.value = highScore;
NSLog(@"Score reporter value: %@", scoreReporter);
[GKScore reportScores:@[scoreReporter] withCompletionHandler:^(NSError *error) {
if (error != nil) {
NSLog(@"Error");
// handle the reporting error
}
}];
}
}这是我检索排行榜的方法:
-(void)displayLeaderboard
{
//NSString *_leaderboardIdentifier = @"flapjacks1";
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
//_leaderboardIdentifier = leaderboardIdentifier;
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
//gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
gameCenterController.leaderboardIdentifier = @"flapjacks1";
[self presentViewController: gameCenterController animated: YES completion:nil];
}
}
}];
}所以,我不确定我是不是错误地访问了排行榜,或者排行榜真的没有数据。我找遍了也找不到答案。非常感谢您的帮助。
发布于 2014-03-23 11:09:06
您是否已将排行榜信息添加到iTunes连接中的应用程序中,并提交了您的应用程序,以便状态为等待二进制上传?您可能还需要在设置应用程序状态后等待24小时,然后才能使用沙盒版本的新排行榜。
您需要确保为您提交的应用程序版本启用游戏中心组件(排行榜和成就),这与您在iTunes连接中创建排行榜的区域是分开的。
发布于 2014-04-16 00:37:19
您确定正在初始化和更新同一个班级的分数吗?如果你在应用委托中初始化,但在其他类中上传分数,那么它可能会产生问题,例如,如下所示:
您已在应用委派中对玩家进行身份验证:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([GameCenterManager isGameCenterAvailable])
{
isGameCenterAvailable = YES;
self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
}
else
{
isGameCenterAvailable = NO;
// The current device does not support Game Center.
}然后想要上传其他班级的分数,使用app委托的对象:
- (void) submitScore2 : (int) curScore
{
if(curScore > 0)
{
[[self delegate].gameCenterManager reportScore: curScore forCategory: self.currentLeaderBoard];
}
} https://stackoverflow.com/questions/22291102
复制相似问题