# GCKSession Class

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

## Overview

An abstract base class representing a session with a receiver device.

Subclasses must implement the [start (GCKSession(Protected))](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#afb4b46285c3a7520833a3950ff49094e) and [endWithAction: (GCKSession(Protected))](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a6422c3e31fda277463648e0542a313e5) methods, and must call the appropriate notifier methods (for example, [notifyDidStartWithSessionID: (GCKSession(Protected))](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a1ebed677b93ece4f7049db8bac5985b4)) to indicate corresponding changes in the session state. Subclasses may also implement [setDeviceVolume: (GCKSession)](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8), [setDeviceMuted: (GCKSession)](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) and [remoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1a8e2db83593db698392d2a7504e7b11) if the device supports such operations.

A session is created and controlled using the session methods in [GCKSessionManager](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session_manager "A class that manages sessions. "), which uses the appropriate [GCKDeviceProvider](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_device_provider "An abstract base class for performing device discovery and session construction. ") to create the session, and then delegates session requests to that [GCKSession](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session "An abstract base class representing a session with a receiver device. ") object.

Since
:   3.0

Inherits NSObject.

Inherited by [GCKCastSession](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_cast_session).

|---|---|
| ## Instance Method Summary ||
| (instancetype) | - [initWithDevice:traits:sessionID:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a6b3f944a300a5a524b00667248c2e501) |
|   | Initializes a new session object for the given device, with default options. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a6b3f944a300a5a524b00667248c2e501) |
|   ||
| (instancetype) | - [initWithDevice:traits:sessionID:sessionOptions:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a07941c164c88cb776255d769041641d2) |
|   | Initializes a new session object for the given device. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a07941c164c88cb776255d769041641d2) |
|   ||
| ([GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request) \*) | - [setDeviceVolume:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8) |
|   | Sets the device's volume. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8) |
|   ||
| ([GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request) \*) | - [setDeviceMuted:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) |
|   | Sets the device's mute state. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) |
|   ||
| (void) | - [start](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#afb4b46285c3a7520833a3950ff49094e) |
|   | Starts the session. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#afb4b46285c3a7520833a3950ff49094e) |
|   ||
| (void) | - [endWithAction:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a6422c3e31fda277463648e0542a313e5) |
|   | Ends the session with the specified action. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a6422c3e31fda277463648e0542a313e5) |
|   ||
| (void) | - [notifyDidStartWithSessionID:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1ebed677b93ece4f7049db8bac5985b4) |
|   | Called by subclasses to notify the framework that the session has been started. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1ebed677b93ece4f7049db8bac5985b4) |
|   ||
| (void) | - [notifyDidFailToStartWithError:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a97935eb165862dda5e182f7c552aad86) |
|   | Called by subclasses to notify the framework that the session has failed to start. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a97935eb165862dda5e182f7c552aad86) |
|   ||
| (void) | - [notifyDidEndWithError:willTryToResume:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a7e7467c9c675d9ef8a04cc3a0eff446f) |
|   | Called by subclasses to notify the framework that the session has ended. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a7e7467c9c675d9ef8a04cc3a0eff446f) |
|   ||
| (void) | - [notifyDidReceiveDeviceVolume:muted:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a67859c55d9f28b889b4f15601ddae9c7) |
|   | Called by subclasses to notify the framework that updated device volume and mute state has been received from the device. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a67859c55d9f28b889b4f15601ddae9c7) |
|   ||
| (void) | - [notifyDidReceiveDeviceStatus:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a0b8183e1c9542c2e5672c5dae4ac6652) |
|   | Called by subclasses to notify the framework that updated status has been received from the device. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a0b8183e1c9542c2e5672c5dae4ac6652) |
|   ||
| (void) | - [notifyDidSuspendWithReason:](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a7ae7a64b8cf88d4263da1f72bd6822b6) |
|   | Deprecated, do not use - implemented as a no-op. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a7ae7a64b8cf88d4263da1f72bd6822b6) |
|   ||
| (void) | - [notifyDidResume](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a925cf3de3d0080f5bf5c833b99b1846e) |
|   | Deprecated, do not use - implemented as a no-op. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a925cf3de3d0080f5bf5c833b99b1846e) |
|   ||

|---|---|
| ## Property Summary ||
| [GCKDevice](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_device) \* | [device](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a30d6130e558b235e37f1cbded2d27ce8) |
|   | The device that this session is associated with. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a30d6130e558b235e37f1cbded2d27ce8) |
|   ||
| NSString \* | [sessionID](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#af77a47f768c15bb8644aed6e75981fd3) |
|   | The current session ID, if any. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#af77a47f768c15bb8644aed6e75981fd3) |
|   ||
| GCKSessionOptions \* | [sessionOptions](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a8c3b1685e8c434b8dc0f5c181028905b) |
|   | The session options, if any. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a8c3b1685e8c434b8dc0f5c181028905b) |
|   ||
| GCKConnectionState | [connectionState](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a15f8c15b38bf0d2f45007166464cf341) |
|   | The current session connection state. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a15f8c15b38bf0d2f45007166464cf341) |
|   ||
| BOOL | [suspended](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#ad6352a0474dc44fb5296b82e7c8cdcf7) |
|   | A flag indicating whether the session is currently suspended. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#ad6352a0474dc44fb5296b82e7c8cdcf7) |
|   ||
| NSString \* | [deviceStatusText](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1821f77bc0c0dc159419608105483a0a) |
|   | The current device status text. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1821f77bc0c0dc159419608105483a0a) |
|   ||
| [GCKSessionTraits](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session_traits) \* | [traits](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#ae0633197f2af22762692e3b5bbca4afe) |
|   | The session traits. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#ae0633197f2af22762692e3b5bbca4afe) |
|   ||
| float | [currentDeviceVolume](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#af4120ee98a679c4ed3abc6ba6b59cf12) |
|   | The current device volume, in the range \[0.0, 1.0\]. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#af4120ee98a679c4ed3abc6ba6b59cf12) |
|   ||
| BOOL | [currentDeviceMuted](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a857055ee238f5af0720d83a6f3281449) |
|   | The current device mute state. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a857055ee238f5af0720d83a6f3281449) |
|   ||
| [GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client) \* | [remoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1a8e2db83593db698392d2a7504e7b11) |
|   | The [GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client "A class for controlling media playback on a Cast receiver. ") object that can be used to control media playback in this session. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a1a8e2db83593db698392d2a7504e7b11) |
|   ||
| [GCKMediaMetadata](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_metadata) \* | [mediaMetadata](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a8dbb7f0afa3b8ef806e7203278638d4f) |
|   | The current media metadata, if any. [More...](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session#a8dbb7f0afa3b8ef806e7203278638d4f) |
|   ||

## Method Detail

|---|---|---|---|
| - (instancetype) initWithDevice: |   | ([GCKDevice](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_device) \*) | *device* |
| traits: |   | (nullable [GCKSessionTraits](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session_traits) \*) | *traits* |
| sessionID: |   | (nullable NSString \*) | *sessionID* |
|   |   |   |   |

Initializes a new session object for the given device, with default options.

Parameters
:

    |---|---|
    | device | The device. |
    | traits | The session traits. |
    | sessionID | The session ID of an existing session, if this object will be used to resume a session; otherwise `nil` if it will be used to start a new session. |


|---|---|---|---|
| - (instancetype) initWithDevice: |   | ([GCKDevice](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_device) \*) | *device* |
| traits: |   | (nullable [GCKSessionTraits](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session_traits) \*) | *traits* |
| sessionID: |   | (nullable NSString \*) | *sessionID* |
| sessionOptions: |   | (nullable GCKSessionOptions \*) | *sessionOptions* |
|   |   |   |   |

Initializes a new session object for the given device.

Parameters
:

    |---|---|
    | device | The device. |
    | traits | The session traits. |
    | sessionID | The session ID of an existing session, if this object will be used to resume a session; otherwise `nil` if it will be used to start a new session. |
    | sessionOptions | The session options, if any; otherwise `nil`. |


Since
:   4.0

|---|---|---|---|---|
| - ([GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request) \*) setDeviceVolume: |   | (float) | *volume* |   |

Sets the device's volume.

This is an asynchronous operation. The default implementation is a no-op that fails the request with a GCKErrorCodeUnsupportedFeature error.

Parameters
:

    |---|---|
    | volume | The new volume. |


Returns
:   A [GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request "An object for tracking an asynchronous request. ") object for tracking the request.

Since
:   3.4; in previous framework versions, this method returned `void`.

|---|---|---|---|---|
| - ([GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request) \*) setDeviceMuted: |   | (BOOL) | *muted* |   |

Sets the device's mute state.

This is an asynchronous operation. The default implementation is a no-op that fails the request with a GCKErrorCodeUnsupportedFeature error.

Parameters
:

    |---|---|
    | muted | The new mute state. |


Returns
:   A [GCKRequest](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_request "An object for tracking an asynchronous request. ") object for tracking the request.

Since
:   3.4; in previous framework versions, this method returned `void`.

|---|---|---|---|
| - (void) start |   |   |   |

Starts the session.

This is an asynchronous operation. Must be overridden by subclasses.

Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#afb4b46285c3a7520833a3950ff49094e).

|---|---|---|---|---|
| - (void) endWithAction: |   | ([GCKSessionEndAction](https://developers.google.com/cast/docs/reference/ios/g_c_k_session_09_protected_8h#a8b2ec2c03fb85ca2f7541cfebadb96cf)) | *action* |   |

Ends the session with the specified action.

This is an asynchronous operation. Must be overridden by subclasses.

Parameters
:

    |---|---|
    | action | The action to take when ending the session; see GCKSessionEndAction for more details. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a6422c3e31fda277463648e0542a313e5).

|---|---|---|---|---|
| - (void) notifyDidStartWithSessionID: |   | (NSString \*) | *sessionID* |   |

Called by subclasses to notify the framework that the session has been started.

Parameters
:

    |---|---|
    | sessionID | The session's unique ID. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a1ebed677b93ece4f7049db8bac5985b4).

|---|---|---|---|---|
| - (void) notifyDidFailToStartWithError: |   | ([GCKError](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_error) \*) | *error* |   |

Called by subclasses to notify the framework that the session has failed to start.

Parameters
:

    |---|---|
    | error | The error that occurred. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a97935eb165862dda5e182f7c552aad86).

|---|---|---|---|
| - (void) notifyDidEndWithError: |   | (nullable NSError \*) | *error* |
| willTryToResume: |   | (BOOL) | *willTryToResume* |
|   |   |   |   |

Called by subclasses to notify the framework that the session has ended.

Parameters
:

    |---|---|
    | error | The error that caused the session to end, if any. Should be `nil` if the session was ended intentionally. |
    | willTryToResume | Whether the session will try to resume itself automatically. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a7e7467c9c675d9ef8a04cc3a0eff446f).

|---|---|---|---|
| - (void) notifyDidReceiveDeviceVolume: |   | (float) | *volume* |
| muted: |   | (BOOL) | *muted* |
|   |   |   |   |

Called by subclasses to notify the framework that updated device volume and mute state has been received from the device.

Parameters
:

    |---|---|
    | volume | The device's current volume. Must be in the range \[0, 1.0\]; |
    | muted | The device's current mute state. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a67859c55d9f28b889b4f15601ddae9c7).

|---|---|---|---|---|
| - (void) notifyDidReceiveDeviceStatus: |   | (nullable NSString \*) | *statusText* |   |

Called by subclasses to notify the framework that updated status has been received from the device.

Parameters
:

    |---|---|
    | statusText | The new status. |


Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a0b8183e1c9542c2e5672c5dae4ac6652).

|---|---|---|---|---|
| - (void) notifyDidSuspendWithReason: |   | ([GCKConnectionSuspendReason](https://developers.google.com/cast/docs/reference/ios/g_c_k_common_8h#a9ac76146a1ad598bb34070e314876a37)) | *reason* |   |

Deprecated, do not use - implemented as a no-op.

**[Deprecated:](https://developers.google.com/cast/docs/reference/ios/deprecated#_deprecated000037)**
:   Do not call.

Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a7ae7a64b8cf88d4263da1f72bd6822b6).

|---|---|---|---|
| - (void) notifyDidResume |   |   |   |

Deprecated, do not use - implemented as a no-op.

**[Deprecated:](https://developers.google.com/cast/docs/reference/ios/deprecated#_deprecated000038)**
:   Do not call.

Provided by category [GCKSession(Protected)](https://developers.google.com/cast/docs/reference/ios/category_g_c_k_session_07_protected_08#a925cf3de3d0080f5bf5c833b99b1846e).

## Property Detail

|---|---|
| |---| | - ([GCKDevice](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_device)\*) device | | readnonatomicstrong |

The device that this session is associated with.

|---|---|
| |---| | - (NSString\*) sessionID | | readnonatomiccopy |

The current session ID, if any.

|---|---|
| |---| | - (GCKSessionOptions\*) sessionOptions | | readnonatomicstrong |

The session options, if any.

Since
:   4.0

|---|---|
| |---| | - (GCKConnectionState) connectionState | | readnonatomicassign |

The current session connection state.

|---|---|
| |---| | - (BOOL) suspended | | readnonatomicassign |

A flag indicating whether the session is currently suspended.

**[Deprecated:](https://developers.google.com/cast/docs/reference/ios/deprecated#_deprecated000036)**
:   [GCKSession](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session "An abstract base class representing a session with a receiver device. ") no longer supports being in suspended state. If needed, move this functionality to a subclass.

|---|---|
| |---| | - (NSString\*) deviceStatusText | | readnonatomiccopy |

The current device status text.

|---|---|
| |---| | - ([GCKSessionTraits](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_session_traits)\*) traits | | readnonatomiccopy |

The session traits.

|---|---|
| |---| | - (float) currentDeviceVolume | | readnonatomicassign |

The current device volume, in the range \[0.0, 1.0\].

|---|---|
| |---| | - (BOOL) currentDeviceMuted | | readnonatomicassign |

The current device mute state.

|---|---|
| |---| | - ([GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client)\*) remoteMediaClient | | readnonatomicstrong |

The [GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client "A class for controlling media playback on a Cast receiver. ") object that can be used to control media playback in this session.

It is `nil` before the session has started, or if the session does not support the [GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client "A class for controlling media playback on a Cast receiver. ") API. Subclasses which provide a [GCKRemoteMediaClient](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_remote_media_client "A class for controlling media playback on a Cast receiver. ") interface must override the getter method.

|---|---|
| |---| | - ([GCKMediaMetadata](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_metadata)\*) mediaMetadata | | readnonatomicstrong |

The current media metadata, if any.

Will be `nil` if the session does not support the media namespace or if no media is currently loaded on the receiver.