# GCKGenericChannel Class

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

## Overview

A generic [GCKCastChannel](https://developers.google.com/cast/docs/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/docs/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/docs/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/docs/reference/ios/interface_g_c_k_cast_channel).

|---|---|
| ## Instance Method Summary ||
| (instancetype) | - [initWithNamespace:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#ac355b4afa1aa5011122abb8340dea7a0) |
|   | Designated initializer. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#ac355b4afa1aa5011122abb8340dea7a0) |
|   ||
| (instancetype) | - [init](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a5c30573fc91241959e4ffe894b539d42) |
|   | Default initializer is not available. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#a5c30573fc91241959e4ffe894b539d42) |
|   ||
| (void) | - [didReceiveTextMessage:](https://developers.google.com/cast/docs/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/docs/reference/ios/interface_g_c_k_generic_channel#ad8d937fc0cfd104f02d7d2951d925cdd) |
|   ||
| (BOOL) | - [sendTextMessage:error:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#ab7f595487ce145f38b2e82e55126789b) |
|   | Sends a text message on this channel. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#ab7f595487ce145f38b2e82e55126789b) |
|   ||
| (NSInteger) | - [generateRequestID](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a8c83fab95cb5d463d28a0426dd4d3e17) |
|   | Generates a request ID for a new message. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#a8c83fab95cb5d463d28a0426dd4d3e17) |
|   ||
| (nullable NSNumber \*) | - [generateRequestNumber](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a204ff88c0c58847a89d59e9f30f85bb6) |
|   | A convenience method which wraps the result of [generateRequestID](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a8c83fab95cb5d463d28a0426dd4d3e17) in an [**NSNumber**](https://goo.gl/gY6NGU). [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#a204ff88c0c58847a89d59e9f30f85bb6) |
|   ||
| (void) | - [didConnect](https://developers.google.com/cast/docs/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/docs/reference/ios/interface_g_c_k_generic_channel#a82a79e3e3f45509df5d0b6b4296a8529) |
|   ||
| (void) | - [didDisconnect](https://developers.google.com/cast/docs/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/docs/reference/ios/interface_g_c_k_generic_channel#a83f1f5750468a8442116610ff3a6a6a9) |
|   ||
| (void) | - [didChangeWritableState:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a35de09db2c61864fb524839569266632) |
|   | Called when the writable state of this channel has changed. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#a35de09db2c61864fb524839569266632) |
|   ||

|---|---|
| ## Property Summary ||
| id\< [GCKGenericChannelDelegate](https://developers.google.com/cast/docs/reference/ios/protocol_g_c_k_generic_channel_delegate-p) \> | [delegate](https://developers.google.com/cast/docs/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/docs/reference/ios/interface_g_c_k_generic_channel#a02f137fc9425b5859d7e1d55d292b535) |
|   ||
| NSString \* | [protocolNamespace](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#abf91f5de1dfcc467c94d9f711f219625) |
|   | The channel's namespace. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#abf91f5de1dfcc467c94d9f711f219625) |
|   ||
| BOOL | [isConnected](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#aef5eb750a266e9549fd81f45d63b36eb) |
|   | A flag indicating whether this channel is currently connected. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#aef5eb750a266e9549fd81f45d63b36eb) |
|   ||
| BOOL | [isWritable](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_channel#a922912c939a4ebb1266d00f550830537) |
|   | A flag indicating whether this channel is currently writable. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_generic_channel#a922912c939a4ebb1266d00f550830537) |
|   ||

## 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/docs/reference/ios/interface_g_c_k_cast_channel#a95b4ed119093a3de422528e8bee9b14e).

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

Default initializer is not available.

|---|---|---|---|---|
| - (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* |
| error: |   | ([GCKError](https://developers.google.com/cast/docs/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/docs/reference/ios/g_c_k_common_8h#aad76567f243bc1b4fb113abd97bf3327) if the channel is not currently connected.

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

A convenience method which wraps the result of [generateRequestID](https://developers.google.com/cast/docs/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.

|---|---|---|---|---|
| - (void) didChangeWritableState: |   | (BOOL) | *isWritable* |   |

Called when the writable state of this channel has changed.

The default implementation is a no-op.

Parameters
:

    |---|---|
    | isWritable | Whether the channel is now writable. |


Since
:   4.0

## Property Detail

|---|---|
| |---| | - (id\<[GCKGenericChannelDelegate](https://developers.google.com/cast/docs/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.

|---|---|
| |---| | - (BOOL) isWritable | | readnonatomicassigninherited |

A flag indicating whether this channel is currently writable.

Since
:   4.0