沙箱排行榜空

use*_*123 7 iphone leaderboard center sandbox

我正在尝试为我的应用制作游戏中心排行榜.我一直在遵循Apple的步骤并遵循GKTapper的示例代码,但我无法在Game Center中显示任何分数.我在iTunes Connect中设置了排行榜.以下是报告分数的代码:

- (void) reportScore: (int64_t) score forCategory: (NSString *) category {
    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
    scoreReporter.value = score;

    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            UIAlertView* alert= [[[UIAlertView alloc] initWithTitle: @"Score Report Failed!" message: [NSString stringWithFormat: @"Reason: %@", [error localizedDescription]] delegate: self cancelButtonTitle: @"Try Again..." otherButtonTitles: NULL] autorelease];
            [alert show];
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)

代码似乎运行正常.警报永远不会显示.但是,当我进入Game Center时,排行榜是空白的.我正在运行Xcode 4.2和iOS 5.任何想法?

小智 -1

reportScoreWithCompletionHandler 的文档说:

“您的应用程序应该保留对分数对象的强引用,直到报告任务完成。”

你正在自动释放。由于任务稍后完成,因此该对象可能在操作执行之前被删除。