A game session you can use to save game data, invite other players, and create turn-based and real-time game apps.


class GKGameSession : NSObject


Use a GKGameSession object to play turn-based and real-time games in iCloud. Every instance of a game session resides inside of an iCloud container. You can create multiple sessions for a single app, allowing players to play several games at once. All of the information for a game session is saved in the owner's iCloud.

Each session can contain a maximum of 100 players. Inside of a session, up to 16 of those players can be connected to each other in real-time. The 16 connected players can be selected from any of the 100 players in the session. You can change a connected player with another player in the session at any time.

After a game session is created, you can save game data in iCloud. Each game session can save a maximum of 512KB data. This prevents games from using a large about of space in a user's iCloud account. This data can be loaded, edited, and saved by anyone in the game session, providing your app provides this behavior. You must ensure that you delete a game session from a user's iCloud after a game is over, otherwise the session will stay in the user's iCloud forever. Game sessions are not automatically removed after a set amount of time. They can only be actively removed.


Accessing Information About a Game Session

var identifier: String

A unique identifier for a game session.

var lastModifiedDate: Date

The date that the game session was last modified.

var lastModifiedPlayer: GKCloudPlayer

The last player to modify the game session.

var maxNumberOfConnectedPlayers: Int

The maximum number of players allowed to connect to the game session at the same time.

var owner: GKCloudPlayer

A player object that represents the owner of the game session.

var players: [GKCloudPlayer]

An array of player objects associated with the game session.

var title: String

The title of the game session.

Inviting Players to a Game Session

func getShareURL(completionHandler: (URL?, Error?) -> Void)

Retrieves the URL used to share a game session.

Saving and Loading Data

func loadData(completionHandler: (Data?, Error?) -> Void)

Retrieves the game data from the current game session.

Listening for Events

class func remove(listener: GKGameSessionEventListener)

Stops listening to the event listener object.

Connecting Players for Real-Time Communication

func players(with: GKConnectionState) -> [GKCloudPlayer]

Retrieves a list of players with the specified connection state.

func send(Data, with: GKTransportType, completionHandler: (Error?) -> Void)

Sends the indicated data to all connected players.

enum GKTransportType

The mechanism used to send messages to other players in a game session.


Inherits From

Conforms To

See Also

Game Sessions

class GKCloudPlayer

The object representing the currently signed-in iCloud user.

protocol GKGameSessionEventListener

An event listener that handles game session events.

class GKGameSessionSharingViewController

A user interface you can use to invite other users into a tvOS game session.

struct GKGameSessionError

Error codes for the GKGameSession domain.

enum GKGameSessionError.Code

Error codes for the GKGameSession domain.

let GKGameSessionErrorDomain: String

The error domain for game sessions.


Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software