Type Method

loadAchievementDescriptionsWithCompletionHandler:

Downloads the achievement descriptions from Game Center.

Declaration

+ (void)loadAchievementDescriptionsWithCompletionHandler:(void (^)(NSArray<GKAchievementDescription *> *descriptions, NSError *error))completionHandler;

Parameters

completionHandler

A block to be called when the download is completed.

The block receives the following parameters:

descriptions

An array of GKAchievementDescription objects containing the achievements in your game. If an error occurred, this value may be non-nil. In this case, the array holds whatever descriptions were downloaded by Game Kit before the error occurred.

error

If an error occurred, this error object describes the error. If the operation completed successfully, this value is nil.

Discussion

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread.

Loading and displaying achievements using a custon interface is a two-step process, with the first step being to call the loadAchievementDescriptionsWithCompletionHandler: method. Calling this method loads all of the achievement descriptions for your game. The second step is to load an image only when it is required. See loadImageWithCompletionHandler: for more details.

Listing 1

Retrieving achievement metadata from Game Center

- (void) retrieveAchievmentMetadata
{
    [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
        ^(NSArray *descriptions, NSError *error) {
            if (error != nil)
            {
                NSLog(@"Faile to load achievement descriptions because of error: %@", error);
            }
            if (descriptions != nil)
            {
                // use the achievement descriptions.
            }
        }];
}

See Also