6

I set up an achievement for passing the first level of my game and it works but when i replay the level and pass it it shows the notification banner again, how can i prevent this from happening?

matt saravitz
  • 157
  • 2
  • 15
  • Take a look at [this](http://stackoverflow.com/questions/4768163/check-if-youve-already-unlocked-an-achievement-in-game-center-gamekit) question - sounds like you're not checking if the achievements already unlocked. – thegrinner Aug 01 '12 at 20:29

2 Answers2

12

Use this method to submit the achievement:

-(void) reportAchievementWithID:(NSString*) achievementID {

    [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {

        if(error) NSLog(@"error reporting ach");

        for (GKAchievement *ach in achievements) {
            if([ach.identifier isEqualToString:achievementID]) { //already submitted
                return ;
            }
        }

        GKAchievement *achievementToSend = [[GKAchievement alloc] initWithIdentifier:achievementID];
        achievementToSend.percentComplete = 100;
        achievementToSend.showsCompletionBanner = YES;
        [achievementToSend reportAchievementWithCompletionHandler:NULL];

    }];

}
Kaan Dedeoglu
  • 14,765
  • 5
  • 40
  • 41
-2

Save that the user has passed the level to NSUserDefaults, then when the user passes the level check NSUserDefaults for your key, if it is there then don't do the achievement code for Game Center.

WhoaItsAFactorial
  • 3,538
  • 4
  • 28
  • 45
  • That works to an extent. I found that if i completed the achievement and then signed out of game center and logged into an account that doest have the achievement completed it makes it impossible to earn for the new player :( – matt saravitz Aug 02 '12 at 01:36
  • you can store it with player alias. but using loadAchievementsWithCompletionHandler is better. – erkanyildiz Aug 08 '12 at 15:44