Overview
TournamentFetcher retrieves the list of tournaments in which the current logged-in user is a participant. It requires both a valid AuthenticationToken with the gaming graph domain and a valid AccessToken.
TournamentUpdater is a companion class that posts a new score to a specific tournament.
Module: FacebookGamingServicesDeclared in:
TournamentFetcher.swift, TournamentUpdater.swift
TournamentFetcher
Initializer
TournamentFetcher with the default GraphRequestFactory. You typically use this initializer directly.
Methods
fetchTournaments(completionHandler:)
Fetches all tournaments where the current user is a participant.
A closure called on completion. On success, receives an array of
Tournament values. On failure, receives a TournamentFetchError.AuthenticationToken.currentmust be non-nil and havegraphDomain == "gaming".AccessToken.currentmust be non-nil.
.failure(.invalidAuthToken) or .failure(.invalidAccessToken) respectively.
TournamentFetchError enum
| Case | Description |
|---|---|
.server(Error) | The Graph API returned an error. The associated value is the underlying error. |
.decoding | The response could not be decoded into [Tournament]. |
.invalidAuthToken | AuthenticationToken.current is nil or not in the gaming domain. |
.invalidAccessToken | AccessToken.current is nil. |
Tournament model
Tournament is a Codable struct that represents a single tournament.
Properties
The unique identifier for this tournament. Corresponds to the
id field in the Graph API response.The timestamp when the tournament ends. If this date is in the past, the tournament has expired.
The display title of the tournament as set during creation.
Custom data attached to the tournament during creation. Available to all game sessions launched from tournament updates.
TournamentConfig struct
TournamentConfig is used when creating a new tournament via ShareTournamentDialog. It describes the configuration of the tournament before it is created on the server.
Initializer
Display title for the tournament.
The end date of the tournament. Defaults to one week after creation if not specified.
How scores are formatted in the leaderboard. Defaults to
TournamentScoreType.numeric.Whether higher or lower scores rank better. Defaults to
TournamentSortOrder.descending.An image to associate with the tournament and include in any posts.
Optional custom data string attached to the tournament. Must be 1000 characters or fewer when stringified.
Properties
Display title of the tournament.
Stored internally as
TimeInterval (Unix timestamp). Converted from Date at initialization.Score formatting preference.
Score ranking order.
Image associated with the tournament.
Custom data string.
TournamentUpdater
TournamentUpdater posts a score update to a specific tournament.
Initializer
Methods
update(tournamentID:score:completionHandler:)
Updates the current user’s score in the specified tournament by ID.
The ID of the tournament to update. Must not be empty.
The new score to record for the current user in this tournament.
A closure called on completion. On success, receives
true. On failure, receives a TournamentUpdaterError.update(tournament:score:completionHandler:)
Updates the current user’s score using a Tournament object.
The tournament to update.
The new score.
A closure called on completion.
TournamentUpdaterError enum
| Case | Description |
|---|---|
.server(Error) | The Graph API returned an error. |
.decoding | The server response could not be decoded. |
.invalidAuthToken | AuthenticationToken.current is nil or not in the gaming domain. |
.invalidAccessToken | AccessToken.current is nil. |
.invalidTournamentID | The provided tournamentID is an empty string. |