Mac Developer Library

Developer

GameKit Framework Reference GKVoiceChat Class Reference

Options
Deployment Target:

On This Page
Language:

GKVoiceChat

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

Inheritance


Conforms To


Import Statement


import GameKit @import GameKit;

Availability


Available in OS X v10.8 and later.
  • Returns whether voice chat may be used on the device.

    Declaration

    Swift

    class func isVoIPAllowed() -> Bool

    Objective-C

    + (BOOL)isVoIPAllowed

    Return Value

    YEStrue if voice chat is available to the game.

    Discussion

    Some countries or phone carriers may restrict the availability of voice over IP services. Before creating a GKVoiceChat object, your game should first check to see whether voice over IP is permitted on the device.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • Starts communication with other participants in a channel.

    Declaration

    Swift

    func start()

    Objective-C

    - (void)start

    Discussion

    When start is called, the app first confirms that it has permission to use the microphone. If this is the first time that the app has tried to access the microphone, a pop-up queries the user for their permission to use voice chat. If the user declines permission, the active flag remains NOfalse and access is not granted.

    After permission is given by the user, the voice chat object connects to the channel and notifies other players connected to the channel that the local player joined the chat. While connected, voice data from other players is played automatically. If the player is connected to the channel and the voice chat object’s active property is YEStrue, then the microphone is sampled and the data sent to the channel.

    A device only connects to a channel when the device has a microphone and is connected via wi-fi. However, your game may configure and start a voice chat channel when the device is not currently capable of using voice chat. If conditions change to allow voice chat—for example, the device connects to a wi-fi network—the GKVoiceChat object then automatically connects to the channel.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • Ends communication with the channel.

    Declaration

    Swift

    func stop()

    Objective-C

    - (void)stop

    Discussion

    When stop is called, the voice chat object disconnects from the channel. You should call stop on a channel before the voice chat object is disposed.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • active active Property

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

    Declaration

    Swift

    var active: Bool

    Objective-C

    @property(assign, getter=isActive, atomic) BOOL active

    Discussion

    When active is YEStrue, the voice chat samples the microphone and transmits the voice data to other players connected to the channel. Default value is NOfalse.

    Only one GKVoiceChat object is allowed to sample the microphone at any given time. When your game sets the active property to YEStrue on a voice chat object, the previous voice chat object that owned the microphone (if there was one) sets its active property to NOfalse.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • A block that is called when a participant changes state.

    Declaration

    Swift

    var playerVoiceChatStateDidChangeHandler: ((GKPlayer!, GKVoiceChatPlayerState) -> Void)!

    Objective-C

    @property(copy, atomic) void (^playerVoiceChatStateDidChangeHandler)( GKPlayer *player, GKVoiceChatPlayerState state)

    Discussion

    Your game sets this property with a block to be called when the state of any participant in the chat changes (including the local player). The block receives the following parameters:

    player

    The GKPlayer object that identifies the player whose status changed.

    state

    The new state of the player. See Player Voice Chat States.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • A block that is called when a participant changes state.

    Declaration

    Swift

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

    Objective-C

    @property(copy, atomic) void (^playerStateUpdateHandler)( NSString *playerID, GKVoiceChatPlayerState state)

    Discussion

    Your game sets this property with a block to be called when the state of any participant in the chat changes (including the local player). The block receives the following parameters:

    playerID

    The player identifier for the player whose status changed.

    state

    The new state of the player. See Player Voice Chat States.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Mutes a participant in the chat.

    Declaration

    Swift

    func setMute(_ isMuted: Bool, forPlayer player: String!)

    Objective-C

    - (void)setMute:(BOOL)isMuted forPlayer:(NSString *)player

    Parameters

    isMuted

    Determines whether the player is to be muted or not.

    player

    The player identifier string for a player in the match.

    Discussion

    When a player is muted, the local player does not hear voice data transmitted by that player.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

  • Mutes a participant in the chat.

    Declaration

    Swift

    func setPlayer(_ player: GKPlayer!, muted isMuted: Bool)

    Objective-C

    - (void)setPlayer:(GKPlayer *)player muted:(BOOL)isMuted

    Parameters

    player

    The GKPlayer object identifying the player to be muted.

    isMuted

    Determines whether the player is to be muted or not.

    Discussion

    When a player is muted, the local player does not hear voice data transmitted by that player.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • volume volume Property

    The volume level for the voice channel.

    Declaration

    Swift

    var volume: Float

    Objective-C

    @property(assign, atomic) float volume

    Discussion

    All voice data received from other participants is mixed and then scaled by the volume property. The volume property has a range between 0.0 and 1.0, inclusive. A volume level of 0.0 means the entire channel is muted; a value of 1.0 plays voice samples at full volume. The default value is 1.0.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • name name Property

    The name of the voice chat (read-only)

    Declaration

    Swift

    var name: String! { get }

    Objective-C

    @property(readonly, copy, atomic) NSString *name

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • players players Property

    An array of GKPlayer objects containing the player identifiers for the players connected to the channel. (read-only)

    Declaration

    Swift

    var players: [AnyObject]! { get }

    Objective-C

    @property(readonly, atomic) NSArray *players

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.10 and later.

  • playerIDs playerIDs (OS X v10.10) Property

    An array of NSString objects containing the player identifiers for the players connected to the channel. (read-only)

    Declaration

    Swift

    var playerIDs: [AnyObject]! { get }

    Objective-C

    @property(readonly, atomic) NSArray *playerIDs

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.10.

Data Types

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

    Declaration

    Swift

    enum GKVoiceChatPlayerState : Int { case Connected case Disconnected case Speaking case Silent case Connecting }

    Objective-C

    enum { GKVoiceChatPlayerConnected, GKVoiceChatPlayerDisconnected, GKVoiceChatPlayerSpeaking, GKVoiceChatPlayerSilent, GKVoiceChatPlayerConnecting }; typedef NSInteger GKVoiceChatPlayerState;

    Constants

    • Connected

      GKVoiceChatPlayerConnected

      The player connected to the channel.

      Available in OS X v10.8 and later.

    • Disconnected

      GKVoiceChatPlayerDisconnected

      The player left the channel.

      Available in OS X v10.8 and later.

    • Speaking

      GKVoiceChatPlayerSpeaking

      The player began speaking.

      Available in OS X v10.8 and later.

    • Silent

      GKVoiceChatPlayerSilent

      The player stopped speaking.

      Available in OS X v10.8 and later.

    • Connecting

      GKVoiceChatPlayerConnecting

      The player is connecting to the channel, but is not yet connected.

      Available in OS X v10.8 and later.

    Import Statement

    import GameKit

    Availability

    Available in OS X v10.8 and later.