Instance Method

send(_:toPeers:with:)

Sends a message encapsulated in a Data instance to nearby peers.

Declaration

func send(_ data: Data, toPeers peerIDs: [MCPeerID], with mode: MCSessionSendDataMode) throws

Parameters

data

An instance containing the message to send.

peerIDs

An array of peer ID instances representing the peers that should receive the message.

mode

The transmission mode to use (reliable or unreliable delivery).

Discussion

This method is asynchronous (nonblocking).

On the recipient device, the session instance calls its delegate instance’s session(_:didReceive:fromPeer:) method with the message after it has been fully received.