Im using Game Kit in my iPhone game, and when I finish a level I check for achievements like this:
if (timeSpentInLevel < 30) {
GKAchievement *ach = [[GKAchievement alloc] initWithIdentifier:@"cryptoquips.achievements.solutiontime.30s"];
ach.percentComplete = 100.0;
ach.showsCompletionBanner = YES;
if (ach != NULL) {
[ach reportAchievementWithCompletionHandler:^(NSError *error) {
if (error!= nil) {
NSLog(@"achievement reporting failed");
}
}];
}
}
but when I do this again in another level, the banner shows anyways, and I assume the points are awarded again. In iTunes Connect I have the achievement set “Achievable More Than Once” to no so this shouldn’t be allowed.
How do I prevent this achievement from being awarded more than once?
You can use loadAchievementsWithCompletionHandler: to do this. It’ll obtain an NSArray of the achievements that have been earned by the player already. Enumerate this array and check to see if any one of them is the achievement you want to unlock, and if none are, unlock it.