问题描述
我已经为此困扰了很长时间了。我了解如何在Game Center中解锁成就,甚至可以使用整个消息传递系统。但是我不知道如何检查成就是否已经解锁:(
I've been stumped on this for quite a long time. I understand how to unlock an achievement in Game Center and I even got a whole messaging system working. But I can't figure out how to check if an achievement has already been unlocked :(
显然这不起作用:
GKAchievement *achievement = [[GKachievement alloc] initWithIdentifier:ident] autorelease];
NSLog(@"%i",achievement.completed);
它始终跟踪 0。
解锁成就确实有效:
GKAchievement *achievement = [[GKachievement alloc] initWithIdentifier:ident] autorelease];
achievement.percentComplete = 100;
所以并不是我在整个成就中犯了一个错误,只是GameKit无法告诉我成就是否已经解锁。
So it's not that I made a mistake in the whole achievement thingy, it's just that GameKit can't tell me if the achievement has already been unlocked or not.
如果有人可以帮助我,我将不胜感激!
I'd be very grateful if someone could help me with this!
推荐答案
要为当前登录的用户加载先前提交的成就,您需要致电:
to load the previously submitted achievements for the currently logged user you need to call:
[GKAchievement loadAchievementsWithCompletionHandler: ^(NSArray *scores, NSError *error)
{
if(error != NULL) { /* error handling */ }
for (GKAchievement* achievement in scores) {
// work with achievement here, store it in your cache or smith
}
}];
您知道Game Center入门的最佳方法-成就和高分者是在苹果在线的演示项目中:
You know the absolutely best way to start with Game Center - achievements and high scorers is to have a look at the demo project Apple has online here:http://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro.html
看看代码-它是非常简单,可以快速掌握发生的情况,并且具有本地成就缓存,提交给不同的排行榜等功能。
Have a look at the code - it's simple enough to quickly grasp what's going on and it features local achievement cache, submitting to different leader boards, etc. etc.
这篇关于检查您是否已经在Game Center / GameKit中解锁成就的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!