Instance Method


Sends the contents of a URL to a peer.


func sendResource(at resourceURL: URL, withName resourceName: String, toPeer peerID: MCPeerID, withCompletionHandler completionHandler: ((Error?) -> Void)? = nil) -> Progress?



A file or HTTP URL.


A name for the resource.


The peer that should receive this resource.


A block that gets called when delivery succeeds or fails. Upon success, the handler is called with an error value of nil. Upon failure, the handle is called with an error object that indicates what went wrong.

Return Value

An NSProgress object that can be used to query the status of the transfer or cancel the transfer.


This method is asynchronous (nonblocking).

On the local device, the completion handler block is called when delivery succeeds or when an error occurs.

On the recipient device, the session calls its delegate’s session(_:didStartReceivingResourceWithName:fromPeer:with:) method as soon as it begins receiving the resource. This method provides an NSProgress object that your app can use to cancel the transfer or check its status.

Upon successful delivery, on the recipient device, the session calls its delegate’s session(_:didFinishReceivingResourceWithName:fromPeer:at:withError:) method. The received resource is written to a file in a temporary location with the same base name; the app is responsible for opening the file or moving it to a permanent location before that delegate method returns.

See Also

Sending Data and Resources

func send(Data, toPeers: [MCPeerID], with: MCSessionSendDataMode)

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