通过标识符检索游戏中心成就 [英] Retrieving game center achievement by identifier

查看:88
本文介绍了通过标识符检索游戏中心成就的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有关游戏中心成就的问题。是否可以通过其标识符检索成就的名称/描述?我试图避免对每个标识符及其相应的名称进行硬编码,所以有没有可以获取名称的解决方案?
谢谢,
萨米人

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.

但是,无法根据其ID向Game Center查询有关一项成就的本地化信息。取而代之的是,您要求提供所有成就的信息,这将为您提供GKAchievementDescription对象数组,最好将其放入以成就ID为键的字典中,然后从该字典中选择适当的GKAchievementDescription对象。

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

该对象为您提供本地化的标题,实现和不实现的描述以及编号奖励的分数以及您在iTunes Connect中指定的图像。

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.

这篇关于通过标识符检索游戏中心成就的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆