Editar

Compartilhar via


MCSession.NearbyConnectionDataForPeer Method

Definition

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

[Foundation.Export("nearbyConnectionDataForPeer:withCompletionHandler:")]
public virtual void NearbyConnectionDataForPeer (MultipeerConnectivity.MCPeerID peerID, MultipeerConnectivity.MCSessionNearbyConnectionDataForPeerCompletionHandler completionHandler);
abstract member NearbyConnectionDataForPeer : MultipeerConnectivity.MCPeerID * MultipeerConnectivity.MCSessionNearbyConnectionDataForPeerCompletionHandler -> unit
override this.NearbyConnectionDataForPeer : MultipeerConnectivity.MCPeerID * MultipeerConnectivity.MCSessionNearbyConnectionDataForPeerCompletionHandler -> unit

Parameters

peerID
MCPeerID

Created from data serialized on a remote peer.

completionHandler
MCSessionNearbyConnectionDataForPeerCompletionHandler

The completion handler called after processing is complete.

Attributes

Remarks

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 ConnectPeer(MCPeerID, NSData) 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:

//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);
    }else{
         throw new Exception(error);
    }
});              

Applies to