Contents

setDataReceiveHandler(_:withContext:)

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

Declaration

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

Parameters

  • handler:

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

  • context:

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

Discussion

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