iOS Guides | Samples

MultipeerConnectivity.MCSession.NearbyConnectionDataForPeer Method

Creates the necessary data for a manually-managed peer connection.


[ObjCRuntime.BindingImpl(ObjCRuntime.BindingImplOptions.GeneratedCode | ObjCRuntime.BindingImplOptions.Optimizable)]
public virtual Void NearbyConnectionDataForPeer (MCPeerID peerID, [ObjCRuntime.BlockProxy(typeof(ObjCRuntime.Trampolines/NIDMCSessionNearbyConnectionDataForPeerCompletionHandler))] MCSessionNearbyConnectionDataForPeerCompletionHandler completionHandler)


Created from data serialized on a remote peer.
The completion handler called after processing is complete.


Application developers may use a non-Multipeer Connectivity discovery technique, such as Bonjour / NSNetService, and manually manage peer connection. However, the peerID used here and in MCSession.ConnectPeer must originate from a NSKeyedArchiver serializing an MCPeerID on the remote peer. (This raises the question: if discovery and enough message-passing code to transmit the peerID is done by Bonjour, what's the advantage of using MPC for further communication? One answer might be the evolution of a legacy system, another answer might lie in the simpler message- and resource-passing of MPC.)

Once the application developer has the peerID, the rest of the code to connect a peer would be:

C# Example

//User code: Perhaps using Bonjour or other discovery and messaging service
var peerID = DeserializedPeerID();
//Request connection data, with completionHandler lambda as continuation
session.NearbyConnectionDataForPeer(peerID, (connectionData, error) => { 
    if(error != null){
        //Note: peerID is serialized version, connectionData is passed in to continuation
        session.ConnectPeer(peerID, connectionData);
         throw new Exception(error);


Namespace: MultipeerConnectivity
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: