Instance Method

sendData:toPeers:withMode:error:

Sends a message encapsulated in an NSData object to nearby peers.

Declaration

- (BOOL)sendData:(NSData *)data toPeers:(NSArray<MCPeerID *> *)peerIDs withMode:(MCSessionSendDataMode)mode error:(NSError * _Nullable *)error;

Parameters

data

An object containing the message to send.

peerIDs

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

mode

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

error

The address of an NSError pointer where an error object should be stored upon error.

Return Value

YES if the message was successfully enqueued for delivery, or NO if an error occurred.

Discussion

This method is asynchronous (nonblocking).

On the recipient device, the session object calls its delegate object’s session:didReceiveData:fromPeer: method with the message after it has been fully received.

See Also

Sending Data and Resources

- startStreamWithName:toPeer:error:

Opens a byte stream to a nearby peer.