An object representing the authenticated Game Center player on a device.


At any given time, only one player may be authenticated on the device; this player must log out before another player can log in. Your game must authenticate the local player before using any Game Center features. Authenticating the player ensures that the player has created an account and is connected to Game Center. To authenticate the local player, retrieve the shared instance of the local player by calling the localPlayer() class method and set its authenticateHandler property.

You can see whether the local player is authenticated by reading the isAuthenticated property. If isAuthenticated is true, then the local player’s other properties are valid, and you can call other Game Center methods.


Accessing the Shared Local Player

func loadRecentPlayers(completionHandler: (([GKPlayer]?, Error?) -> Void)? = nil)

Returns an array of players the local player recently played with.

class func localPlayer()

Retrieves the shared instance of the local player.


var authenticateHandler: ((UIViewController?, Error?) -> Void)?

A handler called to process an authentication-related event.

var isAuthenticated: Bool

A Boolean value that indicates whether a local player is currently signed in to Game Center.

func generateIdentityVerificationSignature(completionHandler: ((URL?, Data?, Data?, UInt64, Error?) -> Void)? = nil)

Generates a signature that allows a third party server to authenticate the local player.

Determining If the Player Is Underage

var isUnderage: Bool

A Boolean value that declares whether the local player is underage.

Working with Leaderboards

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

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

Registering Listeners

func register(GKLocalPlayerListener)

Register a listener for a particular event.

func unregisterAllListeners()

Unregister all listeners in your game.

func unregisterListener(GKLocalPlayerListener)

Unregister a specific listener.

Deprecated Methods and Properties

var friends: [String]?

An array of NSString objects containing the player identifiers for the local player’s friends.

func loadFriendPlayers(completionHandler: (([GKPlayer]?, Error?) -> Void)? = nil)

Retrieves a list of player identifiers for the local player’s friends.

func loadFriends(completionHandler: (([String]?, Error?) -> Void)? = nil)

Retrieves a list of player identifiers for the local player’s friends.



static let GKPlayerAuthenticationDidChangeNotificationName: NSNotification.Name

Posted after the isAuthenticated property of the shared local player object changes. The object property for this notification is a GKLocalPlayer object. Passing nil provides standard Notification Center behavior which is to receive the notification for any object.


Inherits From

See Also


class GKCloudPlayer

The object representing the currently signed in iCloud user.

class GKPlayer

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

class GKBasePlayer

The top level player object containing basic identifying information for a player.

protocol GKLocalPlayerListener

The protocol that handles events for Game Center accounts.

protocol GKInviteEventListener

The protocol that handles invite events from Game Center.