Ios 如何获得高分以提交/报告至游戏中心排行榜?
我在互联网上搜寻这个问题的答案。我在iTunes Connect中设置了排行榜,它显示在我的游戏中,但高分从未报告给排行榜 这是我在GameViewController.m中的排行榜代码Ios 如何获得高分以提交/报告至游戏中心排行榜?,ios,objective-c,sprite-kit,game-center,Ios,Objective C,Sprite Kit,Game Center,我在互联网上搜寻这个问题的答案。我在iTunes Connect中设置了排行榜,它显示在我的游戏中,但高分从未报告给排行榜 这是我在GameViewController.m中的排行榜代码 - (void)authenticateLocalPlayer { GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; localPlayer.authenticateHandler = ^(UIViewController *view
- (void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
if (viewController != nil) [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:viewController animated:YES completion:nil];
else {
if ([GKLocalPlayer localPlayer].authenticated) {
gameCenterEnabled = YES;
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) NSLog(@"%@", [error localizedDescription]);
else _leaderboardIdentifier = leaderboardIdentifier;
}];
}
else gameCenterEnabled = NO;
}
};
}
- (void)showLeaderboard {
GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];
gcViewController.gameCenterDelegate = self;
gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
gcViewController.leaderboardIdentifier = _leaderboardIdentifier;
[self presentViewController:gcViewController animated:YES completion:nil];
}
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController {
[gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
在我的MenuScene.m和EndScene.m中,我有这个代码来显示屏幕上作为标签显示的最佳分数
_labelScoreBest = [[SimpleLabel alloc] initWithText:[NSString stringWithFormat:@"%ld", (long)[[NSUserDefaults standardUserDefaults] integerForKey:@"bestScore"]] fontSize:MS_FONT_SIZE_LABEL_SCORE_BEST position:MS_POSITION_LABEL_SCORE_BEST colorByHEX:MS_FONT_COLOR_LABEL_SCORE_BEST andZPosition:MS_ZPOSITION_LABEL_SCORE_BEST];
这将在屏幕上显示最佳分数。我怎样才能让它报告给我设置的排行榜。我的排行榜标识符由我的GlobalSettings.h中的pragma标记定义为我在iTunes Connect上创建的排行榜ID
我希望所有这些都有意义,并且有人知道如何提供帮助。您必须向GameCenter提交最高分:
func addLeaderboardScore(score: Int64) {
var leaderboardID = "YOURLEADERBOARDID"
let newGCScore = GKScore(leaderboardIdentifier: leaderboardID)
newGCScore.value = score
newGCScore.leaderboardIdentifier = leaderboardID
GKScore.reportScores([newGCScore], withCompletionHandler: {(error) -> Void in
if error != nil {
print("Score not submitted")
}
})
}
还向我的GameCenter代码中添加了NSNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reportScore) name:@"reportScore" object:nil];
事实上,我最终做了一件非常类似于你的func的事情
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reportScore) name:@"reportScore" object:nil];