Instance Method


Loads a photo of this player from Game Center.


iOS, Mac Catalyst, tvOS
- (void)loadPhotoForSize:(GKPhotoSize)size withCompletionHandler:(void (^)(UIImage *photo, NSError *error))completionHandler;
- (void)loadPhotoForSize:(GKPhotoSize)size withCompletionHandler:(void (^)(NSImage *photo, NSError *error))completionHandler;



A constant that determines the size of the photo to load.


A block to be called when the player data is retrieved from Game Center.

The block receives the following parameters:


An image for the player. If an error occurred, this may still be non-nil. In this case, the image reflects an image cached by Game Kit on the device.


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


Listing 1 shows a typical implementation for loading a player’s photo. There is no property that stores the returned photo. You must write your own code to associate player photos with GKPlayer objects.

Listing 1

Loading a player’s photo

- (void) loadPlayerPhoto: (GKPlayer*) player
    [player loadPhotoForSize:GKPhotoSizeSmall withCompletionHandler:^(UIImage *photo, NSError *error) {
        if (photo != nil)
            [self storePhoto: photo forPlayer: player];
        if (error != nil)
            // Handle the error if necessary.

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

Player Photos


The size of a photo loaded by Game Center.