Instance Method

loadImageWithCompletionHandler:

Loads the image property for a completed achievement.

Declaration

iOS, Mac Catalyst, tvOS
- (void)loadImageWithCompletionHandler:(void (^)(UIImage *image, NSError *error))completionHandler;
macOS
- (void)loadImageWithCompletionHandler:(void (^)(NSImage *image, NSError *error))completionHandler;

Parameters

completionHandler

A block to be called when the download is completed.

The block receives the following parameters:

image

The downloaded image. If an error occurred, this value is nil.

error

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

Discussion

Loading and displaying achievements using a custon interface is a two-step process, with the first step being to call the loadAchievementDescriptionsWithCompletionHandler: method. The second step is to call the loadImageWithCompletionHandler: method for each achievement the user has completed. Your game should display the placeholder image until the image is successfully downloaded. After the block is called, the description’s image property holds the same image object that is returned to the block.

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.

In macOS, this class method returns an NSImage object but otherwise works identically.

See Also

Working with Achievement Images

+ incompleteAchievementImage

A common image for incomplete achievements.

+ placeholderCompletedAchievementImage

A common image for completed achievements.