【发布时间】:2015-02-25 17:01:23
【问题描述】:
我正在尝试在 Objective-C 中创建一个排行榜,但没有成功。我一直在这里和其他网站上四处寻找,但我似乎找不到任何有用的东西。我已经在 iTunes Connect 上创建了排行榜,但这是我遇到问题的代码。我收到警告说某些术语已被弃用。
这是我使用的代码:
- (IBAction)ShowLeaderboard:(id)sender {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
if (leaderboardController != nil) { leaderboardController.leaderboardCategory = self;
[self presentModalViewController: leaderboardController animated: YES]; }
}
- (IBAction)SubmitScoreToGameCenter:(id)sender {
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"LeaderboardName"];
scoreReporter.value = HighScoreNumber;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) { if (error != nil){ NSLog(@"Submitting score failed"); }
else { NSLog(@"Submitting score succeeded"); } }];
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{ [self dismissModalViewControllerAnimated:YES];
}
这在 viewDidLoad 中:
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { if (error == nil)
{ NSLog(@"Authentication Successful");
}
else { NSLog(@"Authentication Failed"); } }];
【问题讨论】:
-
@TekayaMarouene 不是很有帮助。 Apple 的文档让我感到困惑……不过,谢谢。
标签: ios objective-c leaderboard