<!--
{
  "availability" : [
    "iOS: 10.0.0 - 12.0.0",
    "iPadOS: 10.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.12.0 - 10.14.0",
    "tvOS: 10.0.0 - 12.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/GKGameSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKGameSession"
  },
  "title" : "GKGameSession"
}
-->

# GKGameSession

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

```
class GKGameSession
```

## Overview

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.

## Topics

### Creating and Loading Game Sessions

[`+  createSessionInContainer:withTitle:maxConnectedPlayers:completionHandler:`](/documentation/GameKit/GKGameSession/createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:))

Creates a new game session inside of an iCloud container.

[`+  loadSessionWithIdentifier:completionHandler:`](/documentation/GameKit/GKGameSession/load(withIdentifier:completionHandler:))

Loads a specific game session.

[`+  loadSessionsInContainer:completionHandler:`](/documentation/GameKit/GKGameSession/loadSessions(inContainer:completionHandler:))

Retrieves all of the game sessions associated with a container.

[`+  removeSessionWithIdentifier:completionHandler:`](/documentation/GameKit/GKGameSession/remove(withIdentifier:completionHandler:))

Removes the specified game session.

### Accessing Information About a Game Session

[`identifier`](/documentation/GameKit/GKGameSession/identifier)

A unique identifier for a game session.

[`lastModifiedDate`](/documentation/GameKit/GKGameSession/lastModifiedDate)

The date that the game session was last modified.

[`lastModifiedPlayer`](/documentation/GameKit/GKGameSession/lastModifiedPlayer)

The last player to modify the game session.

[`maxNumberOfConnectedPlayers`](/documentation/GameKit/GKGameSession/maxNumberOfConnectedPlayers)

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

[`owner`](/documentation/GameKit/GKGameSession/owner)

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

[`players`](/documentation/GameKit/GKGameSession/players)

An array of player objects associated with the game session.

[`title`](/documentation/GameKit/GKGameSession/title)

The title of the game session.

### Inviting Players to a Game Session

[`-  getShareURLWithCompletionHandler:`](/documentation/GameKit/GKGameSession/getShareURL(completionHandler:))

Retrieves the URL used to share a game session.

### Saving and Loading Data

[`-  loadDataWithCompletionHandler:`](/documentation/GameKit/GKGameSession/loadData(completionHandler:))

Retrieves the game data from the current game session.

[`-  saveData:completionHandler:`](/documentation/GameKit/GKGameSession/save(_:completionHandler:))

Saves the current game session data.

### Listening for Events

[`+  addEventListener:`](/documentation/GameKit/GKGameSession/add(listener:))

Adds a new event listener object.

[`+  removeEventListener:`](/documentation/GameKit/GKGameSession/remove(listener:))

Stops listening to the event listener object.

### Connecting Players for Real-Time Communication

[`-  setConnectionState:completionHandler:`](/documentation/GameKit/GKGameSession/setConnectionState(_:completionHandler:))

Sets the connection state for the player.

[`-  playersWithConnectionState:`](/documentation/GameKit/GKGameSession/players(with:))

Retrieves a list of players with the specified connection state.

[`-  sendData:withTransportType:completionHandler:`](/documentation/GameKit/GKGameSession/send(_:with:completionHandler:))

Sends the indicated data to all connected players.

[`GKTransportType`](/documentation/GameKit/GKTransportType)

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

### Communicating Between Players

[`badgedPlayers`](/documentation/GameKit/GKGameSession/badgedPlayers)

An array containing all of the currently badged players.

[`-  clearBadgeForPlayers:completionHandler:`](/documentation/GameKit/GKGameSession/clearBadge(for:completionHandler:))

Clears the badge from the designated players.

[`-  sendMessageWithLocalizedFormatKey:arguments:data:toPlayers:badgePlayers:completionHandler:`](/documentation/GameKit/GKGameSession/sendMessage(withLocalizedFormatKey:arguments:data:to:badgePlayers:completionHandler:))

Sends a message to players in a game session.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)