I’ve caught a few mistakes in GKTapper. Read on to see how the sample performs invalid caching of achievements and to see how it shows incorrect string as leaderboard description in one place.
Invalid caching of achievements
Achievements in -submitAchievement:percentComplete: will never be cached. Also, the comment makes little sense; a sentence appears to be missing.
- (void) submitAchievement: (NSString*) identifier percentComplete: (double) percentComplete { //GameCenter check for duplicate achievements when the achievement is submitted, but if you only want to report // new achievements to the user, then you need to check if it's been earned // before you submit. Otherwise you'll end up with a race condition between loadAchievementsWithCompletionHandler // and reportAchievementWithCompletionHandler. To avoid this, we fetch the current achievement list once, // then cache it and keep it updated with any new achievements. if(self.earnedAchievementCache == NULL) { [GKAchievement loadAchievementsWithCompletionHandler: ^(NSArray *scores, NSError *error) { if(error == NULL) { NSMutableDictionary* tempCache= [NSMutableDictionary dictionaryWithCapacity: [scores count]]; for (GKAchievement* score in tempCache) { [tempCache setObject: score forKey: score.identifier]; } self.earnedAchievementCache= tempCache; [self submitAchievement: identifier percentComplete: percentComplete]; } else { //Something broke loading the achievement list. Error out, and we'll try again the next time achievements submit. [self callDelegateOnMainThread: @selector(achievementSubmitted:error:) withArg: NULL error: error]; } }]; } else }
Where’s the bug? Code iterates over the just-created, empty dictionary “tempCache”. Corrected:
for (GKAchievement* score in scores) // this used to read tempCache
Leaderboard description invalid
Code in method mappedPlayerIDToPlayer:error: contains a small bug:
self.leaderboardHighScoreDescription= @"GameCenter Scores Unavailable"; self.leaderboardHighScoreDescription= @"-";
It should probably read:
self.leaderboardHighScoreDescription= @"GameCenter Scores Unavailable"; self.leaderboardHighScoreString= @"-";
–
via blog.vucica.net