Instance Method


Joins a voice channel.


func voiceChat(withName name: String) -> GKVoiceChat?



The channel to join.

Return Value

An autoreleased voice chat object for the voice channel, or nil if an error occurred.


Calling this method joins a voice channel, creating it if necessary. Your game should keep a strong reference to the voice chat object until the player leaves the channel. All participants who join a channel with the same name are connected to each other.

A single match can have multiple voice chat channels, and any player in the match can join multiple channels simultaneously. For example, a team-based game might create a channel for each team, and a single channel that includes all of the players.

Voice chat objects are dependent on the network connection provided by the match. When the player disconnects from the match, all voice channels associated with that match stop working. Typically, you should exit any voice channels and release any strong references to the channels before disconnecting from the match.

Parental controls may prevent a player from joining a voice chat. If the player is not permitted to join the voice channel, a nil object is returned to your application.

Listing 1 provides code that creates two channels. The first call to the voiceChatWithName: method creates a team channel and the second creates a global channel. The code Memory management both channels.

Listing 1

Creating voice channels

GKMatch* match;
GKVoiceChat *teamChannel = [[match voiceChatWithName:@"redTeam"] retain];
GKVoiceChat *allChannel = [[match voiceChatWithName:@"allPlayers"] retain];