Instance Method


Sets the object that handles data received from other peers connected to the session.


func setDataReceiveHandler(_ handler: Any!, withContext context: UnsafeMutableRawPointer!)



The object you want the session to call when it receives data from other peers.


Arbitrary data to be passed to each invocation of the handler.


The handler must implement a method with the following signature:

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;

where data contains the bytes received from a remote peer, peer is a string that identifies the peer, session is the session that received the data, and context is the same context that was passed into the original call to setDataReceiveHandler(_:withContext:).

See Also

Working with Connected Peers

func send(Data!, toPeers: [Any]!, with: GKSendDataMode)

Transmits a collection of bytes to a list of connected peers.

func sendData(toAllPeers: Data!, with: GKSendDataMode)

Transmits a collection of bytes to all connected peers.

var disconnectTimeout: TimeInterval

A time interval that expresses how long the session waits before it disconnects a nonresponsive peer.

func disconnectFromAllPeers()

Disconnects the session from all connected peers.

func disconnectPeer(fromAllPeers: String!)

Disconnects a connected peer from all peers connected to the session.


Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software