Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Never finished [GKAchievement loadAchievementsWithCompletionHandler:]

I use the function [GKAchievement loadAchievementsWithCompletionHandler:] to restore the current player achievements in initialization. But the completionHander was never called.

- (void)loadAchievements
{
    [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error)
     {
         if (error == nil)     // !!-- if a breakpoint is set here, it would never be reached
         {
             @synchronized(_achievementsDictionary)
             {
                 for (GKAchievement* achievement in achievements)
                     [_achievementsDictionary setObject:achievement forKey:achievement.identifier];
                 NSLog(@"achievements loaded");
             }
         }
         else
         {
             NSLog(@"Error in loading achievements: %@", error);
         }
     }];
}

However, a similar function, [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:] works well:

- (void) retrieveAchievmentMetadata
{
    [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
     ^(NSArray *descriptions, NSError *error) {
         if (error != nil)
         {
             NSLog(@"Error in loading achievement descriptions: %@", error);
         }
         if (descriptions != nil)
         {
             @synchronized(_achievementsMetaDataDictionary)
             {
                 for (GKAchievementDescription* desc in descriptions)
                 {
                     _achievementsMetaDataDictionary[desc.identifier] = desc;
                 }
             }
             NSLog(@"achievement descriptions loaded");
         }
     }];
}

What might be the problem?

like image 806
Wei Xiang Avatar asked Oct 27 '12 14:10

Wei Xiang


1 Answers

It comes a bit late, but maybe it helps someone else.

The fact is that GKAchievement loadAchievementsWithCompletionHandler: loads all the achievements which the local player made progress on. This means, if there are fresh achievements set up in the regarding iTunes Connect app (without any progress), they won't be loaded. Some progress has to be reported first!

On the other hand GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler: is meant to get all the information about every of the available achievements for the regarding iTunes Connect app. The description provides the identifier of the achievement, too.

For a fresh achievement the flow is the following:

  1. Load the achievement description. (GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:)
  2. Report some progress for the achievement to Game Center. The GKAchievement can be created based on data in GKAchievementDescription. (GKAchievementDescription reportAchievements:withCompletionHandler:)
  3. From this point on, load the progress of the achievement to set up your app on start. (GKAchievement loadAchievementsWithCompletionHandler:)
like image 152
GatoCurioso Avatar answered Oct 12 '22 09:10

GatoCurioso