Instance Method

loadDefaultLeaderboardIdentifier(completionHandler:)

Loads the category identifier for the local player’s default leaderboard.

Declaration

func loadDefaultLeaderboardIdentifier(completionHandler: ((String?, Error?) -> Void)? = nil)

Parameters

completionHandler

A block to be called when the request completes.

The block receives the following parameters:

categoryID

The category ID string for the local player’s default leaderboard.

error

If an error occurred, this parameter holds an error object that explains the error. Otherwise, the value of this parameter is nil.

Discussion

This method loads the default leaderboard set in App Store Connect. Use this method to retrieve the default leaderboard.

Listing 1

Loading the default leaderboard for the local player

[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:
(void(^)(NSString *leaderboardIdentifier, NSError *error)) {
    if (error != nil) {
        NSLog(@"Failed to load default leaderboard with value of '%@' because of error: %@", leaderboardIdentifier, error)
    }
    else {
        NSLog(@"Successfully loaded the default leaderboard")
    }
}]

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.

See Also

Working with Leaderboards