Class

GKVoiceChat

A GKVoiceChat object provides a voice channel that allows a set of players in a match to speak with each other.

Overview

In an iOS game, before you can use voice chat, your game must configure an audio session that allows for both play and recording (kAudioSessionCategory_PlayAndRecord). For more information on audio sessions, see Audio Session Programming Guide.

You use the GKMatch object to create a voice chat channel by calling its voiceChat(withName:) method, passing in a string that identifies the name of the channel you want to join. The name is never displayed by GameKit, and you are free to name the channels however you like. You can create multiple channels for the same match. For example, if the match has multiple teams, you might create a separate channel for each team, and an additional channel that holds all of the players in the match.

To connect a player to a channel, call the voice chat object’s start() method. After a channel is started, it receives voice data from other players already in the channel. To allow the player to speak in a channel, set the voice chat object’s isActive property to true. A player can listen to multiple channels simultaneously but may only speak on one channel at any given time.

Your game uses the volume property to set the volume level for an entire channel, and the setPlayer(_:muted:) method to selectively mute other players in the channel.

If there is insufficient bandwidth over wi-fi to maintain a voice chat, GameKit may disconnect individual players from the channel or disband the channel entirely.

Symbols

Determining Whether Voice Chat Is Available

class func isVoIPAllowed()

Returns whether voice chat may be used on the device.

Starting and Stopping Voice Chat

func start()

Starts communication with other participants in a channel.

func stop()

Ends communication with the channel.

Transmitting to Other Players

var isActive: Bool

A Boolean value that states whether the channel is sampling the microphone.

Receiving Updates About Other Participants

var playerVoiceChatStateDidChangeHandler: (GKPlayer, GKVoiceChatPlayerState) -> Void

A block that is called when a participant changes state.

var playerStateUpdateHandler: (String, GKVoiceChatPlayerState) -> Void

A block that is called when a participant changes state.

Deprecated

Controlling Chat Volume

func setMute(Bool, forPlayer: String)

Mutes a participant in the chat.

Deprecated
func setPlayer(GKPlayer, muted: Bool)

Mutes a participant in the chat.

var volume: Float

The volume level for the voice channel.

Channel Properties

var name: String

The name of the voice chat

var players: [GKPlayer]

An array of GKPlayer objects containing the player identifiers for the players connected to the channel.

var playerIDs: [String]

An array of NSString objects containing the player identifiers for the players connected to the channel.

Deprecated

Constants

GKVoiceChatPlayerState

The states returned to your game about other players in a voice chat.

Relationships

Inherits From

Conforms To