Skip to main content
Version: 26.2.9

Classes

Skillz

The main point of interaction with Skillz. This is implemented as a singleton.

skillzInstance

Get a singleton reference to the Skillz SDK.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[Skillz skillzInstance];

{/ Swift /}

Skillz.skillzInstance()

{/ END_DOCUSAURUS_CODE_TABS /}


initWithGameId

Initializes Skillz with the specified game ID.

{/ DOCUSAURUS_CODE_TABS /} {/ Objective-C /}

[[Skillz skillzInstance] initWithGameId:@"12345"
forDelegate:self
withEnvironment:SkillzSandbox
allowExit:NO];

{/ Swift /}

Skillz.skillzInstance().initWithGameId("3382", for: GManager.shared, with: SkillzEnvironment.sandbox, allowExit: true)

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

initWithGameId The ID of your game that is created from the Skillz Developer Console.

forDelegate Reference to a SkillzBaseDelegate instance.

withEnvironment The Skillz server environment your game will run in. It can be either SkillzSandbox or SkillzProduction.

allowExit Specifies if the user can exit the Skillz UI via the sidebar menu. This can be either YES or NO.


launchSkillz

Launches the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] launchSkillz];

{/ Swift /}

Skillz.skillzInstance().launch()

{/ END_DOCUSAURUS_CODE_TABS /}


getMatchInfo

Use this method to fetch the match information of the current match.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

SKZMatchInfo *matchInfo = [[Skillz skillzInstance] getMatchInfo];

{/ Swift /}

let matchInfo = Skillz.skillzInstance().getMatchInfo()

{/ END_DOCUSAURUS_CODE_TABS /}

Returns

An SKZMatchInfo instance.


updatePlayersCurrentScore

This method must be called each time the current player's score changes during a Skillz match.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] updatePlayersCurrentScore:100];

{/ Swift /}

Skillz.skillzInstance().updatePlayersCurrentScore(100)

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

currentScoreForPlayer The players current score as an NSNumber.


displayTournamentResultsWithScore

Reports the player's final score to Skillz, ends the current match, and returns the user to the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] displayTournamentResultsWithScore:100
withCompletion:^(void)
{
NSLog(@"The match has ended, and the user's final score was reported.");
}];

{/ Swift /}

Skillz.skillzInstance().displayTournamentResults(withScore: 100, withCompletion: {
print("The match has ended, and the user's final score was reported.")
})

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

score The player's final score for the current match.

withCompletion Callback to execute after this method has finished executing.


notifyPlayerAbortWithCompletion

Forfeits the match and brings the user back into the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] notifyPlayerAbortMatchWithCompletion:^(void)
{
NSLog(@"The user forfeited the match.");
}];

{/ Swift /}

Skillz.skillzInstance().notifyPlayerAbortMatch(withCompletion: {
print("The user forfeited the match.")
})

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

completion A callback to invoke after the method has completed execution.


setBackgroundMusicFile

Specifies the music file to play as background music while in the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] setBackgroundMusicFile:@"music.mp3"];

{/ Swift /}

Skillz.skillzInstance().backgroundMusicFile = "music.mp3"

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

musicFile Path the music file to play in the background of the Skillz UI.


getBackgroundMusicVolume

Gets the volume for the background music that is played in the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] getBackgroundMusicVolume]];

{/ Swift /}

Skillz.skillzInstance().getBackgroundMusicVolume()

{/ END_DOCUSAURUS_CODE_TABS /}

Returns

A float between 0 and 1.


setBackgroundMusicVolume

Sets the volume of the background music that plays in the Skillz UI.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] setBackgroundMusicVolume:0.5f];

{/ Swift /}

Skillz.skillzInstance().backgroundMusicVolume = 0.5

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

musicVolume A float between 0 and 1, inclusive.


setSFXVolume

Sets the volume for the sound effects in your game.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] setSFXVolume:0.5];

{/ Swift /}

Skillz.skillzInstance().SFXVolume = 0.5
Parameters

volume A float between 0 and 1, inclusive.

{/ END_DOCUSAURUS_CODE_TABS /}


getSFXVolume

Gets the volume for sound effects in your game.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

[[Skillz skillzInstance] getSFXVolume]];

{/ Swift /}

Skillz.skillzInstance().getSFXVolume()

{/ END_DOCUSAURUS_CODE_TABS /}


sendData

Sends a message to all clients connected to this match. This will trigger SkillzSyncDelegate::onDidReceiveData: on all clients connected to the current match.

Note: NSData passed to this function are limited to a certain size based on the game, and this function will assert if over that size. (2048 bytes currently).

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)sendData:(NSData * _Nonnull)data;

{/ Swift /}

func send(_ data: Data) {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

message The message to be sent.


isMatchCompleted

This will return whether or not another client connected to this match has called either displaySynchronousTournamentResultsWithScore or initiateSynchronousAbortWithCompletion: to end the match.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (BOOL)isMatchCompleted;

{/ Swift /}

func isMatchCompleted() -> Bool {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Returns

A boolean indicating whether or not the match has been completed.


Protocols

SkillzDelegate

Implement this protocol to support asynchronous matches.

tournamentWillBegin

Required

Called when a typical Skillz tournament will launch. You should use this method for constructing a new game based on the supplied argument.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)tournamentWillBegin:(NSDictionary *)gameParameters
withMatchInfo:(SKZMatchInfo *)matchInfo;

{/ Swift /}

func tournamentWillBegin(_ gameParameters: [AnyHashable : Any]!, with matchInfo: SKZMatchInfo!)

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

gameParameters A dictionary containing gameplay parameters that were set up for the type of match being played.

matchInfo Contains information about the match that is starting.


skillzWillExit

Optional

Called when the Skillz UI will exit via the sidebar menu.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)skillzWillExit;

{/ Swift /}

func skillzWillExit()

{/ END_DOCUSAURUS_CODE_TABS /}


skillzWillLaunch

Optional

Called right before before the Skillz UI launches. Use this to clean up any state needed before you launch Skillz.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)skillzWillLaunch;

{/ Swift /}

func skillzWillLaunch() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


skillzHasFinishedLaunching

Optional

This method will be called once the Skillz UI has finished displaying. Use this to clean up your view hierarchy.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)skillzHasFinishedLaunching;

{/ Swift /}

func skillzHasFinishedLaunching() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


SkillzSyncDelegate

Implement this protocol if your game supports synchronous matches.

onOpponentHasReconnected

Required

This method will be called when the opponent player has successfully reconnected within the timeout. This will allow you to resume the game.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onOpponentHasReconnected:(SKZSyncPlayerId)playerId;

{/ Swift /}

func onOpponentHasReconnected(_ playerId: SKZSyncPlayerId) {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

Id ID of player who has reconnected.


onOpponentHasLostConnection

Required

This method will be called when the opponent player's connection has failed and Skillz is attempting to reconnect. This will allow you to pause the game while waiting for the player to reconnect.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onOpponentHasLostConnection:(SKZSyncPlayerId)playerId;

{/ Swift /}

func onOpponentHasLostConnection(_ playerId: SKZSyncPlayerId) {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

playerId Id of the player who is attempting to reconnect.


onOpponentHasLeftMatch

Required

This method will be called when the opponent player leaves the match (due to connection failure or abort) and is unable to rejoin. At this point, Skillz handles the player as if they have aborted. At this point your game should gracefully end the match and report the current player's score.

Note: If you receive this message without a corresponding "onOpponentHasLostConnection:" call, you should assume the player has manually aborted.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onOpponentHasLeftMatch:(SKZSyncPlayerId)playerId;

{/ Swift /}

func onOpponentHasLeftMatch(_ playerId: SKZSyncPlayerId) {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

playerId ID of the player who has permanently left the match.


onCurrentPlayerHasReconnected

Required

This method will be called when the current player has successfully reconnected within the timeout. This will allow you to resume the game.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onCurrentPlayerHasReconnected;

{/ Swift /}

func onCurrentPlayerHasReconnected() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


onCurrentPlayerHasLostConnection

Required

This method will be called when the current player's connection has failed and Skillz is attempting to reconnect. This will allow you to pause the game while waiting for the player to reconnect.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onCurrentPlayerHasLostConnection;

{/ Swift /}

func onCurrentPlayerHasLostConnection() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


onCurrentPlayerHasLeftMatch

Required

This method will be called when the current player leaves the match (due to connection failure or abort) and is unable to rejoin. At this point, Skillz handles the player as if they have aborted.

Note: You should follow up by calling "notifyPlayerAbortWithCompletion:" at your convenience.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onCurrentPlayerHasLeftMatch;

{/ Swift /}

func onCurrentPlayerHasLeftMatch() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


onDidReceiveData

Optional

When another instance of your client connected to the same match passes a message using the below sendData:, this method will be called on all other clients.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onDidReceiveData:(NSData * _Nonnull)data;

{/ Swift /}

func onDidReceive(_ data: Data) {
}

{/ END_DOCUSAURUS_CODE_TABS /}

Parameters

data The message sent by your client


onMatchCompleted

Optional

This method will be triggered on all clients when one client has explicitly reported a score or aborted.

Note: This method will be called from a background thread.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

- (void)onMatchCompleted;

{/ Swift /}

func onMatchCompleted() {
}

{/ END_DOCUSAURUS_CODE_TABS /}


Constants

SkillzEnvironment

Use Sandbox as you are developing and testing your game with Skillz, and Production before going live on both Skillz and the iOS app store.

{/ DOCUSAURUS_CODE_TABS /}

{/ Objective-C /}

SkillzSandbox
SkillzProduction

{/ Swift /}

SkillzEnvironment.sandbox
SkillzEnvironment.production

{/ END_DOCUSAURUS_CODE_TABS /}