Type Method

loadAchievements(completionHandler:)

Loads previously submitted achievement progress for the local player from Game Center.

Declaration

class func loadAchievements(completionHandler: (([GKAchievement]?, Error?) -> Void)? = nil)

Parameters

completionHandler

A block to be called when the download is completed.

The block receives the following parameters:

achievements

An array of GKAchievement objects that represents all progress reported to Game Center for the local player. If an error occurred, this parameter may be non-nil, in which case the array holds whatever achievement information Game Kit was able to fetch.

error

If an error occurred, this 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. Listing 1 shows an example of how to load the local player’s achievements.

Listing 1

Loading achievement progress

- (void) loadAchievements
{    [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
        if (error != nil)
        {
            NSLog(@"Error in loading achievements: %@", error);
        }
        if (achievements != nil)
        {
            // Process the array of achievements.
        }
       }];
}

See Also