matt saravitz
matt saravitz

Reputation: 157

Game Center achievement unlocking multiple times

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?

Upvotes: 6

Views: 1543

Answers (2)

Kaan Dedeoglu
Kaan Dedeoglu

Reputation: 14841

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];

    }];

}

Upvotes: 12

WhoaItsAFactorial
WhoaItsAFactorial

Reputation: 3558

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.

Upvotes: -2

Related Questions