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?
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:
GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
)GKAchievementDescription
. (GKAchievementDescription reportAchievements:withCompletionHandler:
)GKAchievement loadAchievementsWithCompletionHandler:
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With