createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)
Creates a new game session inside of an iCloud container.
Declaration
class func createSession(inContainer containerName: String?, withTitle title: String, maxConnectedPlayers maxPlayers: Int, completionHandler: @escaping @Sendable (GKGameSession?, (any Error)?) -> Void)class func createSession(inContainer containerName: String?, withTitle title: String, maxConnectedPlayers maxPlayers: Int) async throws -> GKGameSessionParameters
- containerName:
A
Stringvalue representing the iCloud container for the game session. - title:
A
Stringvalue representing the title of the game session. - maxPlayers:
An
Integervalue indicating the maximum number of players allowed in the game session. - completionHandler:
A block that is called after a new game session has been created.
- gameSession
A
GKGameSessionobject containing information about the newly created game session.- error
If an error occurred, this parameter holds an error object that explains the error. Otherwise, the value of this parameter is nil. See
GameKit Constantsfor a list of error codes specific to GameKit.
Discussion
The container name must be a valid iCloud container associated with your app. After a user has finished a game and is done with a game session, remove the created game session from iCloud using remove(withIdentifier:completionHandler:). See iCloud Design Guide for more information on incorporating iCloud in your app.