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.

Topics

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.

enum GKVoiceChatPlayerState

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.

Deprecated
var playerStateUpdateHandler: (String, GKVoiceChatPlayerState) -> Void

A block that is called when a participant changes state.

Deprecated
func setMute(Bool, forPlayer: String)

Mutes a participant in the chat.

Deprecated

Relationships

Inherits From

Conforms To

See Also

Realtime Matches

class GKMatch

A GKMatch object provides a peer-to-peer network between a group of devices that are connected to Game Center. Matches provide transmit both voice and game data. Your game never directly allocates GKMatch objects. Instead, it uses the GKMatchmaker class to programmatically find a match with other interested players or a GKMatchmakerViewController object to display a user interface to the player.

protocol GKMatchDelegate

The GKMatchDelegate protocol is implemented to receive status updates and network data from players connected to a GKMatch object.

class GKMatchRequest

A GKMatchRequest object is used to specify the parameters for a new live or turn-based match. You initialize a match request object, then pass it to another object to actually create the match. The kind of object you pass it to depends on which kind of match you want and whether you want to display the standard matchmaking user interface. See Table 1.