# GCKSession Class

[Instance Methods](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#pub-methods) \| [Properties](https://developers.google.com/cast/v3/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/v3/reference/ios/category_g_c_k_session_07_protected_08#afb4b46285c3a7520833a3950ff49094e), [endAndStopCasting: (GCKSession(Protected))](https://developers.google.com/cast/v3/reference/ios/category_g_c_k_session_07_protected_08#aaa21a8d6e182e9b787a1be8b77e54bfb), [suspendWithReason: (GCKSession(Protected))](https://developers.google.com/cast/v3/reference/ios/category_g_c_k_session_07_protected_08#af3db6940482f74430f78cae38c1f39fd), and [resume (GCKSession(Protected))](https://developers.google.com/cast/v3/reference/ios/category_g_c_k_session_07_protected_08#a401056ff15ff1823daadad633e50081f) methods, and must call the appropriate notifier methods (for example, [notifyDidStartWithSessionID: (GCKSession(Protected))](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8), [setDeviceMuted: (GCKSession)](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) and [remoteMediaClient](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session_manager "A class that manages sessions. "), which uses the appropriate [GCKDeviceProvider](https://developers.google.com/cast/v3/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/v3/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/v3/reference/ios/interface_g_c_k_cast_session).

|---|---|
| ## Instance Method Summary ||
| (instancetype) | - [initWithDevice:traits:sessionID:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a7ad6799c8399164160d4c767f4243b02) |
|   | Initializes a new session object for the given device. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a7ad6799c8399164160d4c767f4243b02) |
|   ||
| ([GCKRequest](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_request) \*) | - [setDeviceVolume:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8) |
|   | Sets the device's volume. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a68dcca2fdf1f4aebee394f0af56e7fb8) |
|   ||
| ([GCKRequest](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_request) \*) | - [setDeviceMuted:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) |
|   | Sets the device's mute state. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aac1dc4461b6d7ae6f1f5f9dc93cafebd) |
|   ||
| (void) | - [start](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#afb4b46285c3a7520833a3950ff49094e) |
|   | Starts the session. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#afb4b46285c3a7520833a3950ff49094e) |
|   ||
| (void) | - [endAndStopCasting:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aaa21a8d6e182e9b787a1be8b77e54bfb) |
|   | Ends the session. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aaa21a8d6e182e9b787a1be8b77e54bfb) |
|   ||
| (void) | - [suspendWithReason:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#af3db6940482f74430f78cae38c1f39fd) |
|   | Suspends the session for the given reason. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#af3db6940482f74430f78cae38c1f39fd) |
|   ||
| (void) | - [resume](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a401056ff15ff1823daadad633e50081f) |
|   | Resumes the session. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a401056ff15ff1823daadad633e50081f) |
|   ||
| (void) | - [notifyDidStartWithSessionID:](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session#a1ebed677b93ece4f7049db8bac5985b4) |
|   ||
| (void) | - [notifyDidFailToStartWithError:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a120392568d2087c8cd46fe4096ceae4b) |
|   | Called by subclasses to notify the framework that the session has failed to start. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a120392568d2087c8cd46fe4096ceae4b) |
|   ||
| (void) | - [notifyDidResume](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a925cf3de3d0080f5bf5c833b99b1846e) |
|   | Called by subclasses to notify the framework that the session been resumed. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a925cf3de3d0080f5bf5c833b99b1846e) |
|   ||
| (void) | - [notifyDidSuspendWithReason:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a7ae7a64b8cf88d4263da1f72bd6822b6) |
|   | Called by subclasses to notify the framework that the session has been suspended. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a7ae7a64b8cf88d4263da1f72bd6822b6) |
|   ||
| (void) | - [notifyDidEndWithError:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aeb3fd1eea6f90c132ae7c632f9433674) |
|   | Called by subclasses to notify the framework that the session has ended. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#aeb3fd1eea6f90c132ae7c632f9433674) |
|   ||
| (void) | - [notifyDidReceiveDeviceVolume:muted:](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session#a67859c55d9f28b889b4f15601ddae9c7) |
|   ||
| (void) | - [notifyDidReceiveDeviceStatus:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a526045dd13d1ad3d00096be2543e8ab7) |
|   | Called by subclasses to notify the framework that updated status has been received from the device. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a526045dd13d1ad3d00096be2543e8ab7) |
|   ||

|---|---|
| ## Property Summary ||
| [GCKDevice](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_device) \* | [device](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a30d6130e558b235e37f1cbded2d27ce8) |
|   | The device that this session is associated with. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a30d6130e558b235e37f1cbded2d27ce8) |
|   ||
| NSString \* | [sessionID](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#af77a47f768c15bb8644aed6e75981fd3) |
|   | The current session ID, if any. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#af77a47f768c15bb8644aed6e75981fd3) |
|   ||
| [GCKConnectionState](https://developers.google.com/cast/v3/reference/ios/g_c_k_common_8h#aeb91bcb8e8dc2ae918494213cb33426c) | [connectionState](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a15f8c15b38bf0d2f45007166464cf341) |
|   | The current session connection state. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a15f8c15b38bf0d2f45007166464cf341) |
|   ||
| BOOL | [suspended](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#ad6352a0474dc44fb5296b82e7c8cdcf7) |
|   | A flag indicating whether the session is currently suspended. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#ad6352a0474dc44fb5296b82e7c8cdcf7) |
|   ||
| NSString \* | [deviceStatusText](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a1821f77bc0c0dc159419608105483a0a) |
|   | The current device status text. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a1821f77bc0c0dc159419608105483a0a) |
|   ||
| [GCKSessionTraits](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_traits) \* | [traits](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#ae0633197f2af22762692e3b5bbca4afe) |
|   | The session traits. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#ae0633197f2af22762692e3b5bbca4afe) |
|   ||
| float | [currentDeviceVolume](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session#af4120ee98a679c4ed3abc6ba6b59cf12) |
|   ||
| BOOL | [currentDeviceMuted](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a857055ee238f5af0720d83a6f3281449) |
|   | The current device mute state. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a857055ee238f5af0720d83a6f3281449) |
|   ||
| [GCKRemoteMediaClient](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_remote_media_client) \* | [remoteMediaClient](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a1a8e2db83593db698392d2a7504e7b11) |
|   | The [GCKRemoteMediaClient](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_session#a1a8e2db83593db698392d2a7504e7b11) |
|   ||
| [GCKMediaMetadata](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_media_metadata) \* | [mediaMetadata](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a8dbb7f0afa3b8ef806e7203278638d4f) |
|   | The current media metadata, if any. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session#a8dbb7f0afa3b8ef806e7203278638d4f) |
|   ||

## Method Detail

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

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. |


|---|---|---|---|---|
| - ([GCKRequest](https://developers.google.com/cast/v3/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/v3/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/v3/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/v3/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/v3/reference/ios/category_g_c_k_session_07_protected_08#afb4b46285c3a7520833a3950ff49094e).

|---|---|---|---|---|
| - (void) endAndStopCasting: |   | (BOOL) | *stopCasting* |   |

Ends the session.

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

Parameters
:

    |---|---|
    | stopCasting | Whether to stop casting content to the receiver. |


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

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

Suspends the session for the given reason.

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

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

|---|---|---|---|
| - (void) resume |   |   |   |

Resumes the session.

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

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

|---|---|---|---|---|
| - (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/v3/reference/ios/category_g_c_k_session_07_protected_08#a1ebed677b93ece4f7049db8bac5985b4).

|---|---|---|---|---|
| - (void) notifyDidFailToStartWithError: |   | (NSError \*) | *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/v3/reference/ios/category_g_c_k_session_07_protected_08#a120392568d2087c8cd46fe4096ceae4b).

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

Called by subclasses to notify the framework that the session been resumed.

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

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

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

Parameters
:

    |---|---|
    | reason | The reason for the suspension. |


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

|---|---|---|---|---|
| - (void) notifyDidEndWithError: |   | (NSError \*__nullable) | *error* |   |

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. |


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

|---|---|---|---|
| - (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/v3/reference/ios/category_g_c_k_session_07_protected_08#a67859c55d9f28b889b4f15601ddae9c7).

|---|---|---|---|---|
| - (void) notifyDidReceiveDeviceStatus: |   | (NSString \*__nullable) | *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/v3/reference/ios/category_g_c_k_session_07_protected_08#a526045dd13d1ad3d00096be2543e8ab7).

## Property Detail

|---|---|
| |---| | - ([GCKDevice](https://developers.google.com/cast/v3/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.

|---|---|
| |---| | - ([GCKConnectionState](https://developers.google.com/cast/v3/reference/ios/g_c_k_common_8h#aeb91bcb8e8dc2ae918494213cb33426c)) connectionState | | readnonatomicassign |

The current session connection state.

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

A flag indicating whether the session is currently suspended.

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

The current device status text.

|---|---|
| |---| | - ([GCKSessionTraits](https://developers.google.com/cast/v3/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/v3/reference/ios/interface_g_c_k_remote_media_client)\*) remoteMediaClient | | readnonatomicstrong |

The [GCKRemoteMediaClient](https://developers.google.com/cast/v3/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/v3/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/v3/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/v3/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.