Make sure you have already unlocked the achievement in Game Center / GameKit

I have been at a standstill for quite some time. I understand how to unlock an achievement in Game Center, and I even got a whole messaging system. But I can’t figure out how to check if the achievement is already unlocked :(

This does not seem to work:

GKAchievement *achievement = [[GKachievement alloc] initWithIdentifier:ident] autorelease]; NSLog(@"%i",achievement.completed); 

It always tracks "0".

Unlocking achievements really works:

 GKAchievement *achievement = [[GKachievement alloc] initWithIdentifier:ident] autorelease]; achievement.percentComplete = 100; 

So, it’s not that I made a mistake in the whole achievement of the goal, it’s just that GameKit cannot tell me if the achievement is already unlocked or not.

I would really appreciate if anyone could help me!

+3
source share
2 answers

To download previously provided achievements for the current registered user who needs to call:

 [GKAchievement loadAchievementsWithCompletionHandler: ^(NSArray *scores, NSError *error) { if(error != NULL) { /* error handling */ } for (GKAchievement* achievement in scores) { // work with achievement here, store it in your cache or smith } }]; 

You know that the best way to start with Game Center is to achieve achievements and high scores, to see the demo project that Apple has here: http://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro. html

Take a look at the code - simply enough to quickly understand what is happening, and it has a local achievement cache, sending to different leaderboards, etc. etc.

+4
source

I am going to start implementing this myself.

From what I read in the docs, what I think you need to do is call

 loadAchievementsWithCompletionHandler: 

http://developer.apple.com/library/ios/documentation/GameKit/Reference/GKAchievement_Ref/Reference/Reference.html#//apple_ref/doc/uid/TP40009959-CH1-SW1

0
source

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


All Articles