我希望我的应用程序检查成就是否完成,然后我写了下一篇:
-(void)checkAchievements{
NSString* identifier = NULL;
double percentComplete = 0;
if (self.SavedScore >= 100) {
identifier = kAchivement100Taps;
percentComplete = 100.0;
}
if (self.SavedScore >= 500) {
identifier = kAchivement500Taps;
percentComplete = 100.0;
}
[...more similar achievements...]
if(identifier!= NULL){
[self.gameCenterManager submitAchievement: identifier percentComplete: percentComplete];
}
}
这种方法是否正确? 谢谢!
答案 0 :(得分:0)
这是检查成就是否完成的正确方法:
- (void) loadAchievements
{
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error)
{
if (error == nil)
{
for (GKAchievement* achievement in achievements)
GKAchievement *gkAchmt = [[[GKAchievement alloc] initWithIdentifier: achievement.achievementId] autorelease];
if (gkAchmt.isCompleted) {
// This achievement is achieved.
}
}
}];
}
因此,如果您要在数组中同步您的成就,您可以执行以下操作:
for (Achievement *achievement in arrAchievementsToSync) {
GKAchievement *gkAchmt = [[[GKAchievement alloc] initWithIdentifier: achievement.achievementId] autorelease];
if (!gkAchmt.isCompleted) {
[self submitAchievement:gkAchmt percentComplete:100.0f];
}
}