# GCKGenericChannel Class

[Instance Methods](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#pub-methods) \| [Properties](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#properties) GCKGenericChannel Class Reference

## Overview

A generic [GCKCastChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel "A virtual communication channel for exchanging messages between a Cast sender and a Cast receiver...") implementation, suitable for use when subclassing is not desired.

[GCKGenericChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel "A generic GCKCastChannel implementation, suitable for use when subclassing is not desired...") forwards message and connectivity events to its delegate, and has no processing logic of its own.

See [GCKGenericChannelDelegate](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_generic_channel_delegate-p "The GCKGenericChannel delegate protocol. ") for the delegate protocol.

Inherits [GCKCastChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel).

|---|---|
| ## Instance Method Summary ||
| (instancetype) | - [initWithNamespace:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#ac355b4afa1aa5011122abb8340dea7a0) |
|   | Designated initializer. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#ac355b4afa1aa5011122abb8340dea7a0) |
|   ||
| (instancetype) | - [init](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a5c30573fc91241959e4ffe894b539d42) |
|   | Default initializer is not available. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a5c30573fc91241959e4ffe894b539d42) |
|   ||
| (void) | - [didReceiveTextMessage:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#ad8d937fc0cfd104f02d7d2951d925cdd) |
|   | Called when a text message has been received on this channel. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#ad8d937fc0cfd104f02d7d2951d925cdd) |
|   ||
| (BOOL) | - [sendTextMessage:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a536d42cdfb9d56d9ed10c3f75c493985) |
|   | Sends a text message on this channel. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a536d42cdfb9d56d9ed10c3f75c493985) |
|   ||
| (BOOL) | - [sendTextMessage:error:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a4033e8c0bcfbaf3916d6e38260930c43) |
|   | Sends a text message on this channel. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a4033e8c0bcfbaf3916d6e38260930c43) |
|   ||
| (NSInteger) | - [generateRequestID](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a8c83fab95cb5d463d28a0426dd4d3e17) |
|   | Generates a request ID for a new message. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a8c83fab95cb5d463d28a0426dd4d3e17) |
|   ||
| (NSNumber \*__nullable) | - [generateRequestNumber](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a87356e48d904a3c88f4a05bd077226cb) |
|   | A convenience method which wraps the result of [generateRequestID](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a8c83fab95cb5d463d28a0426dd4d3e17) in an [**NSNumber**](https://goo.gl/gY6NGU). [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a87356e48d904a3c88f4a05bd077226cb) |
|   ||
| (void) | - [didConnect](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a82a79e3e3f45509df5d0b6b4296a8529) |
|   | Called when this channel has been connected, indicating that messages can now be exchanged with the Cast device over this channel. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a82a79e3e3f45509df5d0b6b4296a8529) |
|   ||
| (void) | - [didDisconnect](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a83f1f5750468a8442116610ff3a6a6a9) |
|   | Called when this channel has been disconnected, indicating that messages can no longer be exchanged with the Cast device over this channel. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a83f1f5750468a8442116610ff3a6a6a9) |
|   ||

|---|---|
| ## Property Summary ||
| id\< [GCKGenericChannelDelegate](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_generic_channel_delegate-p) \> | [delegate](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a02f137fc9425b5859d7e1d55d292b535) |
|   | The delegate for receiving notifications about changes in the channel's state. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a02f137fc9425b5859d7e1d55d292b535) |
|   ||
| NSString \* | [protocolNamespace](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#abf91f5de1dfcc467c94d9f711f219625) |
|   | The channel's namespace. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#abf91f5de1dfcc467c94d9f711f219625) |
|   ||
| BOOL | [isConnected](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#aef5eb750a266e9549fd81f45d63b36eb) |
|   | A flag indicating whether this channel is currently connected. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#aef5eb750a266e9549fd81f45d63b36eb) |
|   ||
| [GCKDeviceManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_device_manager) \* | [deviceManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a31b5b45235120ca70905ee5ac26cd3cf) |
|   | The device manager with which this channel is registered, if any. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_generic_channel#a31b5b45235120ca70905ee5ac26cd3cf) |
|   ||

## Method Detail

|---|---|---|---|---|
| - (instancetype) initWithNamespace: |   | (NSString \*) | *protocolNamespace* |   |

Designated initializer.

Parameters
:

    |---|---|
    | protocolNamespace | The namespace for this channel. This namespace must be unique across all channels used by a given application. |


Implements [GCKCastChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a95b4ed119093a3de422528e8bee9b14e).

|---|---|---|---|
| - (instancetype) init |   |   |   |

Default initializer is not available.

Implemented in [GCKMediaControlChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_media_control_channel#a5032b83abf997c43da88cab84899973e), and [GCKGameManagerChannel](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_game_manager_channel#a925959d8dd686de2bf10d6b84dd4d9a0).

|---|---|---|---|---|
| - (void) didReceiveTextMessage: |   | (NSString \*) | *message* |   |

Called when a text message has been received on this channel.

The default implementation is a no-op.

Parameters
:

    |---|---|
    | message | The message. |


|---|---|---|---|---|
| - (BOOL) sendTextMessage: |   | (NSString \*) | *message* |   |

Sends a text message on this channel.

Parameters
:

    |---|---|
    | message | The message. |


Returns
:   `YES` on success or `NO` if the message could not be sent (because the channel is not connected, or because the send buffer is too full at the moment).

**[Deprecated:](https://developers.google.com/cast/v3/reference/ios/deprecated#_deprecated000002)**
:   Use [sendTextMessage:error:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a4033e8c0bcfbaf3916d6e38260930c43) which provides detailed error information.

|---|---|---|---|
| - (BOOL) [sendTextMessage:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a536d42cdfb9d56d9ed10c3f75c493985) |   | (NSString \*) | *message* |
| error: |   | ([GCKError](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_error) \*__nullable \*__nullable) | *error* |
|   |   |   |   |

Sends a text message on this channel.

Parameters
:

    |---|---|
    | message | The message. |
    | error | A pointer at which to store the error result. May be `nil`. |


Returns
:   `YES` on success or `NO` if the message could not be sent.

|---|---|---|---|
| - (NSInteger) generateRequestID |   |   |   |

Generates a request ID for a new message.

Returns
:   The generated ID, or [kGCKInvalidRequestID](https://developers.google.com/cast/v3/reference/ios/g_c_k_common_8h#aad76567f243bc1b4fb113abd97bf3327) if the channel is not currently connected.

|---|---|---|---|
| - (NSNumber \* __nullable) generateRequestNumber |   |   |   |

A convenience method which wraps the result of [generateRequestID](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_channel#a8c83fab95cb5d463d28a0426dd4d3e17) in an [**NSNumber**](https://goo.gl/gY6NGU).

Returns
:   The generated ID, or `nil` if the channel is not currently connected.

|---|---|---|---|
| - (void) didConnect |   |   |   |

Called when this channel has been connected, indicating that messages can now be exchanged with the Cast device over this channel.

The default implementation is a no-op.

|---|---|---|---|
| - (void) didDisconnect |   |   |   |

Called when this channel has been disconnected, indicating that messages can no longer be exchanged with the Cast device over this channel.

The default implementation is a no-op.

## Property Detail

|---|---|
| |---| | - (id\<[GCKGenericChannelDelegate](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_generic_channel_delegate-p)\>) delegate | | readwritenonatomicweak |

The delegate for receiving notifications about changes in the channel's state.

|---|---|
| |---| | - (NSString\*) protocolNamespace | | readnonatomiccopyinherited |

The channel's namespace.

|---|---|
| |---| | - (BOOL) isConnected | | readnonatomicassigninherited |

A flag indicating whether this channel is currently connected.

|---|---|
| |---| | - ([GCKDeviceManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_device_manager)\*) deviceManager | | readnonatomicweakinherited |

The device manager with which this channel is registered, if any.

**[Deprecated:](https://developers.google.com/cast/v3/reference/ios/deprecated#_deprecated000001)**
:   If this channel was not registered with the deprecated [GCKDeviceManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_device_manager "A controller for Cast devices. ") class, this will be `nil`.