ive updated my app for IOS 7 and game center has a few things deprecated such as loading and dismissing the leaderboard and achievements how can i fix them it says GKLeaderboardViewController is deprecated
- (IBAction)LeaderBoardsButton:(id)sender {
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.leaderboardDelegate = self;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}
{
AudioServicesPlaySystemSound(SoundID);
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:NULL];
{
AudioServicesPlaySystemSound(SoundID2);
}
}
- (IBAction)AchievementsButton:(id)sender {
GKAchievementViewController *achievements = [[GKAchievementViewController
alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[self presentViewController:achievements animated:YES completion:NULL];
}
{
AudioServicesPlaySystemSound(SoundID);
}
}
- (void)achievementViewControllerDidFinish:(GKAchievementViewController
*)viewController
{
[self dismissViewControllerAnimated:YES completion:NULL];
{
AudioServicesPlaySystemSound(SoundID2);
}
}
i am reporting the score like this
- (IBAction)ShareScore:(id)sender {
[self.gameCenterManager reportScore: counter forCategory: self.currentLeaderBoard];
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.category = self.currentLeaderBoard;
leaderboardController.timeScope = GKLeaderboardTimeScopeToday;
leaderboardController.leaderboardDelegate = self;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}
{
AudioServicesPlaySystemSound(SoundID);
}
}
iOS 7 combines the leaderboards, achievements, etc. controllers together into the GKGameCenterViewController
class. You use the viewState
parameter to control which view you want displayed.
You'll want to do something like this to present/dismiss the leaderboards:
- (void) presentLeaderboards {
GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init];
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
Similarly, for presenting achievements, you can do this:
- (void) presentAchievements {
GKGameCenterViewController* gameCenterController = [[GKGameCenterViewController alloc] init];
gameCenterController.viewState = GKGameCenterViewControllerStateAchievements;
gameCenterController.gameCenterDelegate = self;
[self presentViewController:gameCenterController animated:YES completion:nil];
}
Reporting score would look something like this:
- (void) reportHighScore:(NSInteger) highScore forLeaderboardId:(NSString*) leaderboardId {
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKScore* score = [[GKScore alloc] initWithLeaderboardIdentifier:leaderboardId];
score.value = highScore;
[GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
if (error) {
NSLog(@"error: %@", error);
}
}];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With