Class

GKPlayer

An object that provides information about a player on Game Center.

Overview

Every player account on Game Center is permanently assigned a unique player identifier string. Your game should use this string to store per-player information or to disambiguate between players. In most cases, Game Kit classes return player identifier strings to your game. For example, in a multiplayer match, the GKMatch object’s playerIDs property contains an array of the player identifiers for all the players connected to the match.

To load information about a set of players, your game calls the loadPlayers(forIdentifiers:withCompletionHandler:) method, passing in an array of identifier strings. Your completion handler is called after the player data is downloaded from Game Center. For performance and resource reasons, player objects returned by the loadPlayers(forIdentifiers:withCompletionHandler:) method do not include player photos. To load the photo associated with a player, call the player object’s loadPhoto(forSize:withCompletionHandler:) method.

The concept of guest players is introduced in iOS 9. Guest players are treated exactly like authenticated players for Game Center multiplayer purposes. However, guest players cannot earn achievements, post to leaderboards, or participate in challenges. Create a guest player with the anonymousGuestPlayer(withIdentifier:) method.

Symbols

Loading Player Details

Identifying the Player

var playerID: String?

A string assigned by Game Center to uniquely identify a player.

Player Details

var alias: String?

A string chosen by the player to identify themselves to other players.

var displayName: String?

A string to display for the player.

var isFriend: Bool

A Boolean value that indicates whether this player is a friend of the local player.

Deprecated

Player Photos

GKPhotoSize

The size of a photo loaded by Game Center.

Creating a Guest Player

class func anonymousGuestPlayer(withIdentifier: String)

Creates a new guest player with the designated identifier.

var guestIdentifier: String?

A developer created string used to identify a guest player.

Notifications

let GKPlayerDidChangeNotificationName: String

Posted when a player object’s data changes.

Relationships

Inherits From