Retrieving game center achievement by identifier

萝らか妹 提交于 2019-12-05 10:07:21

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!