---
title: GKSession
framework: gamekit
role: symbol
role_heading: Class
path: gamekit/gksession
---

# GKSession

A GKSession object provides the ability to discover and connect to nearby iOS devices using Bluetooth or Wi-fi.

## Declaration

```swift
class GKSession
```

## Overview

Overview Sessions primarily work with peers. A peer is any iOS device made visible by creating and configuring a GKSession object. Each peer is identified by a unique identifier, called a peer id (peerID) string. Your application can use a peerID string to obtain a user-readable name for a remote peer and to attempt to connect to that peer. Similarly, your session’s peer ID is visible to other nearby peers. After a connection is established, your application uses the remote peer’s ID to address data packets that it wants to send. Peers discover other peers by using a unique string to identify the service they implement, called a session ID (sessionID). Sessions can be configured to broadcast a session ID (as a server), to search for other peers advertising with that session ID (as a client), or to act as both a server and a client simultaneously (as a peer. Your application controls the behavior of a session through a delegate that implements the GKSessionDelegate protocol. The delegate is called when remote peers are discovered, when those peers attempt to connect to the session, and when the state of a remote peer changes. Your application also provides a data handler to the session so that the session can forward data it receives from remote peers. The data handler can be a separate object or the same object as the delegate. When Bluetooth is turned on, Wi-Fi download speeds drastically decrease while the device is searching for other Bluetooth enabled devices. After the Bluetooth discovery time has completed, Wi-Fi speeds return to normal. GKSession methods are thread-safe and may be called from any thread. However, the session always calls its delegate on the main thread.

## Topics

### Creating a Session

- [init(sessionID:displayName:sessionMode:)](gamekit/gksession/init(sessionid:displayname:sessionmode:).md)

### Setting and Getting the Delegate

- [delegate](gamekit/gksession/delegate.md)

### Searching for Other Peers

- [isAvailable](gamekit/gksession/isavailable.md)

### Obtaining Information About Other Peers

- [peers(with:)](gamekit/gksession/peers(with:).md)
- [displayName(forPeer:)](gamekit/gksession/displayname(forpeer:).md)

### Connecting to a Remote Peer

- [connect(toPeer:withTimeout:)](gamekit/gksession/connect(topeer:withtimeout:).md)
- [cancelConnect(toPeer:)](gamekit/gksession/cancelconnect(topeer:).md)

### Receiving Connections from a Remote Peer

- [acceptConnection(fromPeer:)](gamekit/gksession/acceptconnection(frompeer:).md)
- [denyConnection(fromPeer:)](gamekit/gksession/denyconnection(frompeer:).md)

### Working with Connected Peers

- [setDataReceiveHandler(_:withContext:)](gamekit/gksession/setdatareceivehandler(_:withcontext:).md)
- [send(_:toPeers:with:)](gamekit/gksession/send(_:topeers:with:).md)
- [sendData(toAllPeers:with:)](gamekit/gksession/senddata(toallpeers:with:).md)
- [disconnectTimeout](gamekit/gksession/disconnecttimeout.md)
- [disconnectFromAllPeers()](gamekit/gksession/disconnectfromallpeers().md)
- [disconnectPeer(fromAllPeers:)](gamekit/gksession/disconnectpeer(fromallpeers:).md)

### Information about the Session

- [displayName](gamekit/gksession/displayname.md)
- [peerID](gamekit/gksession/peerid.md)
- [sessionID](gamekit/gksession/sessionid.md)
- [sessionMode](gamekit/gksession/sessionmode.md)

### Constants

- [GKSendDataMode](gamekit/gksenddatamode.md)
- [GKSessionMode](gamekit/gksessionmode.md)
- [GKPeerConnectionState](gamekit/gkpeerconnectionstate.md)
- [The Session Error Domain](gamekit/the-session-error-domain.md)
- [GKSessionError.Code](gamekit/gksessionerror-swift.struct/code.md)
- [GKSessionError](gamekit/gksessionerror-swift.struct.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Deprecated classes

- [GKAchievementViewController](gamekit/gkachievementviewcontroller.md)
- [GKChallengeEventHandler](gamekit/gkchallengeeventhandler.md)
- [GKChallengesViewController](gamekit/gkchallengesviewcontroller.md)
- [GKChallenge](gamekit/gkchallenge.md)
- [GKScoreChallenge](gamekit/gkscorechallenge.md)
- [GKAchievementChallenge](gamekit/gkachievementchallenge.md)
- [GKCloudPlayer](gamekit/gkcloudplayer.md)
- [GKGameCenterViewController](gamekit/gkgamecenterviewcontroller.md)
- [GKGameSession](gamekit/gkgamesession.md)
- [GKGameSessionSharingViewController](gamekit/gkgamesessionsharingviewcontroller.md)
- [GKFriendRequestComposeViewController](gamekit/gkfriendrequestcomposeviewcontroller.md)
- [GKLeaderboardViewController](gamekit/gkleaderboardviewcontroller.md)
- [GKPeerPickerController](gamekit/gkpeerpickercontroller.md)
- [GKScore](gamekit/gkscore.md)
- [GKTurnBasedEventHandler](gamekit/gkturnbasedeventhandler.md)
