0

我希望我的应用程序检查成就是否完成,我写了下一个:

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

这种方法正确吗?谢谢!

4

1 回答 1

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];
    }
}
于 2012-09-17T17:26:47.533 回答