Instance Method

challengeComposeControllerWithMessage:players:completionHandler:

Provides a challenge compose view controller with a preformatted message for the achievement and pre-selected GKPlayer objects.

Declaration

iOS, tvOS
- (UIViewController *)challengeComposeControllerWithMessage:(NSString *)message players:(NSArray<GKPlayer *> *)players completionHandler:(GKChallengeComposeCompletionBlock)completionHandler;
macOS
- (NSViewController *)challengeComposeControllerWithMessage:(NSString *)message players:(NSArray<GKPlayer *> *)players completionHandler:(GKChallengeComposeCompletionBlock)completionHandler;

Parameters

message

The message that is sent to other players. This message can be edited by the player.

players

An array of GKPlayer objects that contains the player identifiers that the challenge is to be sent to.

completionHandler

A block to be called after the view controller has been displayed. Contains the reason the handler was called and all player identifiers that the challenge was sent to.

Return Value

A UIViewController view that contains the player identifiers and the challenge message.

Discussion

The view controller returned is presented modally from the top view controller. After the view controller is displayed and the player sends or cancels the challenge, the completion handler block is called.

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

Issuing Achievement Challenges

- selectChallengeablePlayers:withCompletionHandler:

Finds the subset of players that can earn an achievement.