Never finished [GKAchievement loadAchievementsWithCompletionHandler:]

I use the [GKAchievement loadAchievementsWithCompletionHandler:] function to restore the player’s current achievements during initialization. But Harder’s completion 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 could be the problem?

+4
source share
2 answers

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

The fact is that GKAchievement loadAchievementsWithCompletionHandler: loads all the achievements to which the local player has advanced. This means that if there are new achievements in iTunes Connect (without any success), they will not be downloaded. First you need to report some progress!

On the other hand, GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler: designed to get all the information about every available achievement regarding the iTunes Connect app. The description also contains the ID of the achievement.

For a new achievement, the flow is as follows:

  • Download a description of the achievement. ( GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
  • Report some achievements in achieving the Game Center. GKAchievement can be created based on data in the GKAchievementDescription . ( GKAchievementDescription reportAchievements:withCompletionHandler:
  • From now on, download the achievement progress to configure the application at startup. ( GKAchievement loadAchievementsWithCompletionHandler:
+5
source

Have you verified that the returned NSArray descriptions NSArray not contain 0 elements?

  if( !descriptions.count ) printf( "User has not submitted _any_ progress on _any_ achievements\n" ) ; else for (GKAchievementDescription* desc in descriptions) .. 

Please note that the descriptions array here returns only the collection of achievements that this user previously reported on the progress, not the array of all achievements ever registered in GameCenter for this application.

0
source

Source: https://habr.com/ru/post/1442490/


All Articles