# GCKSessionManager Class

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

## Overview

A class that manages sessions.

The method [startSessionWithDevice: (GCKSessionManager)](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a211d476c2e9b265ed7510d12f4b29c02) is used to create a new session with a given [GCKDevice](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_device "An object representing a receiver device. "). The session manager uses the [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. ") for that device type to construct a new [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, to which it then delegates all session requests.

[GCKSessionManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager "A class that manages sessions. ") handles the automatic resumption of suspended sessions (that is, resuming sessions that were ended when the application went to the background, or in the event that the application crashed or was forcibly terminated by the user). When the application resumes or restarts, the session manager will wait for a short time for the device provider of the suspended session's device to discover that device again, and if it does, it will attempt to reconnect to that device and re-establish the session automatically.

If the application has created a [GCKUICastButton](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_u_i_cast_button "A subclass of UIButton that implements a \"Cast\" button. ") without providing a target and selector, then a user tap on the button will display the default Cast dialog and it will automatically start and stop sessions based on user selection or disconnection of a device. If however the application is providing its own device selection/control dialog UI, then it should use the [GCKSessionManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager "A class that manages sessions. ") directly to create and control sessions.

Whether or not the application uses the [GCKSessionManager](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager "A class that manages sessions. ") to control sessions, it can attach a [GCKSessionManagerListener](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_session_manager_listener-p "The GCKSessionManager listener protocol. ") to be notified of session events, and can also use KVO to monitor the [connectionState](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a8b48906a8910f328343e2260e6bef6a0 "The current session connection state. ") property to track the current session lifecycle state.

Since
:   3.0

Inherits NSObject.

|---|---|
| ## Instance Method Summary ||
| (instancetype) | - [init](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a07ab817e881f3d955085151a99557c9c) |
|   | Default initializer is not available. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a07ab817e881f3d955085151a99557c9c) |
|   ||
| (BOOL) | - [startSessionWithDevice:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a211d476c2e9b265ed7510d12f4b29c02) |
|   | Starts a new session with the given device. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a211d476c2e9b265ed7510d12f4b29c02) |
|   ||
| (BOOL) | - [suspendSessionWithReason:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a08fad03c5798c6a2d450c25607cdbedb) |
|   | Suspends the current session. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a08fad03c5798c6a2d450c25607cdbedb) |
|   ||
| (BOOL) | - [endSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a74f2884baa895acecd87913dad9ff4a2) |
|   | Ends the current session. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a74f2884baa895acecd87913dad9ff4a2) |
|   ||
| (BOOL) | - [endSessionAndStopCasting:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a25fb07952abae96d2a10fd9a479ca4e3) |
|   | Ends the current session, optionally stopping casting. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a25fb07952abae96d2a10fd9a479ca4e3) |
|   ||
| (BOOL) | - [hasConnectedSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a640482415ab7629bc0ddd1572324dac9) |
|   | Tests if a session is currently being managed by this session manager, and it is currently connected. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a640482415ab7629bc0ddd1572324dac9) |
|   ||
| (BOOL) | - [hasConnectedCastSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a217f41ee128a1b41c6f28e4f61d9c45b) |
|   | Tests if a Cast session is currently being managed by this session manager, and it is currently connected. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a217f41ee128a1b41c6f28e4f61d9c45b) |
|   ||
| (void) | - [addListener:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a0effcfdce9ff74022704bae7663acc48) |
|   | Adds a listener for receiving notifications. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a0effcfdce9ff74022704bae7663acc48) |
|   ||
| (void) | - [removeListener:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#ac096beffff7ddf55028207bccda5d2fd) |
|   | Removes a listener that was previously added with [addListener:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a0effcfdce9ff74022704bae7663acc48). [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#ac096beffff7ddf55028207bccda5d2fd) |
|   ||

|---|---|
| ## Property Summary ||
| [GCKSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session) \* | [currentSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#aab8948bb35c1d8a64aba2802286ac9ee) |
|   | The current session, if any. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#aab8948bb35c1d8a64aba2802286ac9ee) |
|   ||
| [GCKCastSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_session) \* | [currentCastSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#ae111cd45eb4a4cbc69b0e3e096c561eb) |
|   | The current cast session, if any. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#ae111cd45eb4a4cbc69b0e3e096c561eb) |
|   ||
| [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_manager#a8b48906a8910f328343e2260e6bef6a0) |
|   | The current session connection state. [More...](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a8b48906a8910f328343e2260e6bef6a0) |
|   ||

## Method Detail

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

Default initializer is not available.

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

Starts a new session with the given device.

This is an asynchronous operation.

Parameters
:

    |---|---|
    | device | The device to use for this session. |


Returns
:   `YES` if the operation has been started successfully, `NO` if there is a session currently established or if the operation could not be started.

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

Suspends the current session.

This is an asynchronous operation.

Parameters
:

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


Returns
:   `YES` if the operation has been started successfully, `NO` if there is no session currently established or if the operation could not be started.

|---|---|---|---|
| - (BOOL) endSession |   |   |   |

Ends the current session.

This is an asynchronous operation.

Returns
:   `YES` if the operation has been started successfully, `NO` if there is no session currently established or if the operation could not be started.

|---|---|---|---|---|
| - (BOOL) endSessionAndStopCasting: |   | (BOOL) | *stopCasting* |   |

Ends the current session, optionally stopping casting.

This is an asynchronous operation.

Parameters
:

    |---|---|
    | stopCasting | Whether casting of content on the receiver should be stopped when the session is ended. |


Returns
:   `YES` if the operation has been started successfully, `NO` if there is no session currently established or if the operation could not be started.

|---|---|---|---|
| - (BOOL) hasConnectedSession |   |   |   |

Tests if a session is currently being managed by this session manager, and it is currently connected.

This will be `YES` if the session state is [GCKConnectionStateConnected](https://developers.google.com/cast/v3/reference/ios/g_c_k_common_8h#aeb91bcb8e8dc2ae918494213cb33426caba2e53f0e5cb065225b5b4a574b86ec2).

|---|---|---|---|
| - (BOOL) hasConnectedCastSession |   |   |   |

Tests if a Cast session is currently being managed by this session manager, and it is currently connected.

This will be `YES` if the session state is [GCKConnectionStateConnected](https://developers.google.com/cast/v3/reference/ios/g_c_k_common_8h#aeb91bcb8e8dc2ae918494213cb33426caba2e53f0e5cb065225b5b4a574b86ec2) and the session is a Cast session.

|---|---|---|---|---|
| - (void) addListener: |   | (id\< [GCKSessionManagerListener](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_session_manager_listener-p) \>) | *listener* |   |

Adds a listener for receiving notifications.

Parameters
:

    |---|---|
    | listener | The listener to add. |


|---|---|---|---|---|
| - (void) removeListener: |   | (id\< [GCKSessionManagerListener](https://developers.google.com/cast/v3/reference/ios/protocol_g_c_k_session_manager_listener-p) \>) | *listener* |   |

Removes a listener that was previously added with [addListener:](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session_manager#a0effcfdce9ff74022704bae7663acc48).

Parameters
:

    |---|---|
    | listener | The listener to remove. |


## Property Detail

|---|---|
| |---| | - ([GCKSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_session)\*) currentSession | | readnonatomicstrong |

The current session, if any.

|---|---|
| |---| | - ([GCKCastSession](https://developers.google.com/cast/v3/reference/ios/interface_g_c_k_cast_session)\*) currentCastSession | | readnonatomicstrong |

The current cast session, if any.

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

The current session connection state.