I have a question related to Game center achievements. Is it possible to retrieve the name/description of an achievement by its identifier? I am trying to avoid hardcoding every identifier with its corresponding name, so is there a solution that can get the name? thanks, Sami
Of course, that's exactly why you have localization support for achievements (as well as leaderboards) inside iTunes Connect.
However, there is no way to ask Game Center about localized info for just one achievement based on it's ID. Instead, you ask for info about all achievements which gives you an array of GKAchievementDescription objects which would be best to put into a dictionary where keys are achievement IDs and then you select a proper GKAchievementDescription object from that dictionary.
NSMutableDictionary *achievementDescriptions = [[NSMutableDictionary alloc] init];
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:^(NSArray *descriptions, NSError *error) {
if (error != nil) {
NSLog(@"Error getting achievement descriptions: %@", error);
}
for (GKAchievementDescription *achievementDescription in descriptions) {
[achievementDescriptions setObject:achievementDescription forKey:achievementDescription.identifier];
}
}];
And then when you want to display info for some achievement:
GKAchievementDescription *achievementDescription = [achievementDescriptions objectForKey:currentAchievement.identifier];
This object gives you a localized title, description for when it is achieved and unachieved, as well as number of points it awards and an image you specified in iTunes Connect.
来源:https://stackoverflow.com/questions/6949005/retrieving-game-center-achievement-by-identifier