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


class GKVoiceChat : NSObject


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.


Determining Whether Voice Chat Is Available

class func isVoIPAllowed() -> Bool

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

enum GKVoiceChat.PlayerState

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

Controlling Chat Volume

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.

Deprecated Methods and Properties

var playerIDs: [String]

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

var playerStateUpdateHandler: (String, GKVoiceChat.PlayerState) -> Void

A block that is called when a participant changes state.

func setMute(Bool, forPlayer: String)

Mutes a participant in the chat.



Inherits From

Conforms To

See Also

Real-Time Matches

class GKMatch

A peer-to-peer network between a group of devices that are connected to Game Center.

class GKMatchRequest

A set of parameters for a new live or turn-based match.