iOS Guides | Samples

MonoTouch.MultipeerConnectivity Namespace

The MultipeerConnectivity namespace provides local (WiFi/Bluetooth) peer-to-peer messaging and data connections.


Introduced in iOS 7, Multipeer Connectivity (MPC) allows iOS devices to discover and communicate with other nearby iOS devices. "Nearby" devices are those within Bluetooth range, on the same WiFi network segment, or using WiFi peer connectivity. Additionally, MPC can bridge through connected peers: a WiFi-only iOS device can bridge to a Bluetooth-only iOS device via a peer that has both WiFi and Bluetooth . MPC is considerably easier to use than Zero-Configuration Networking (zeroconf), but MPC is not available for cross-platform scenarios.

Multipeer Connectivity has two phases: discovery and the session. The role of the discovery phase is to associate an MCSession object on each device with an MCSession object on the peer devices. In the session phase, the MCSession object is the channel through which devices communicate and its lifecycle events are associated with connections, disconnections, transmissions, and receptions.

The MCSession is instantiated by the application developer. During the discovery phase, there are two roles: advertisers that broadcast their willingness to connect to a certain protocol and browsers that discover these advertisers and invite them to sessions.

Advertising is managed by either the stock MCAdvertiserAssistant or custom controller that uses a MCNearbyServiceAdvertiser. Similarly, browsing is managed by a UIViewController, either the stock MCBrowserViewController or a custom controller that uses a MCNearbyServiceBrowser object to programmatically discover peers. Once a peer is discovered, an invitation is sent with MCNearbyServiceBrowser.InvitePeer). The application user interacts with a system dialog informing them of the invitation. If they accept, the MCSession connects.

The following image shows the sequence of functions with programmatic advertising and browsing:

Create a new MCNearbyServiceAdvertiserDelegate and assign it to the MCNearbyServiceAdvertiser.Delegate property.Create a new MCNearbyServiceBrowserDelegate and assign it to MCNearbyServiceBrowser.Delegate property.Discovery and connection is taken care of by the delegate objects for the MCNearbyServiceAdvertiser and MCNearbyServiceBrowser.
The advertiser may instantiate a new MCSession now or wait until it receives an invitation.Instantiate a new MCSession.The browser should maintain a reference to a single MCSession object no matter how many peers ultimately connect.
StartAdvertisingPeer StartBrowsingForPeers Advertiser and browser must use identical serviceType strings to identify their protocol / application. Peer IDs should be unique to each device.
The system will call FoundPeer, passing in a reference to the MCNearbyServiceBrowser. The application developer calls InvitePeer, passing in a reference to the previously-created MCSession.The callback is likely to occur on a background thread. If the application developer wishes to update the display, they must use InvokeOnMainThread.
The system will call DidReceiveInvitationFromPeer. To connect the devices, the application developer must invoke the passed-in invitationHandler with it's context argument set to true and it's session argument set to an MCSession.The callback is likely to occur on a background thread. If the application developer wishes to update the display, they must use InvokeOnMainThread.
Once the devices are connected, the MCSession objects can be used to transmit messages and data between devices.


IMCAdvertiserAssistantDelegateInterface representing the required methods (if any) of the protocol MCAdvertiserAssistantDelegate.
IMCBrowserViewControllerDelegateInterface representing the required methods (if any) of the protocol MCBrowserViewControllerDelegate.
IMCNearbyServiceAdvertiserDelegateInterface representing the required methods (if any) of the protocol MCNearbyServiceAdvertiserDelegate.
IMCNearbyServiceBrowserDelegateInterface representing the required methods (if any) of the protocol MCNearbyServiceBrowserDelegate.
IMCSessionDelegateInterface representing the required methods (if any) of the protocol MCSessionDelegate.
MCAdvertiserAssistantA convenience class that manages the process of advertising for multipeer connectivity and interacting with the application user.
MCAdvertiserAssistantDelegateA delegate object that provides events for the presentation or dismissal of an invitation by a MCAdvertiserAssistant.
MCAdvertiserAssistantDelegate_ExtensionsExtension methods to the IMCAdvertiserAssistantDelegate interface to support all the methods from the MCAdvertiserAssistantDelegate protocol.
MCBrowserViewControllerA standard UIViewController that provides a user experience for browsing for peers.
MCBrowserViewControllerDelegateA delegate object that provides events relating to the presentation of discovered peers and the application user's selection or cancellation of them.
MCBrowserViewControllerDelegate_ExtensionsExtension methods to the IMCBrowserViewControllerDelegate interface to support all the methods from the MCBrowserViewControllerDelegate protocol.
MCEncryptionPreferenceAn enumeration whose values specify whether an MCSession should encrypt its connection. Used with MCSession.MCSession(MCPeerID,SecIdentity,MCEncryptionPreference).
MCErrorAn enumeration whose values specify various errors relating to multipeer connectivity.
MCErrorExtensionsExtension methods for the MonoTouch.MultipeerConnectivity.MCError enumeration.
MCNearbyServiceAdvertiserProvides programmatic control for advertising the device for multipeer connectivity.
MCNearbyServiceAdvertiserDelegateA delegate object that exposes events relating to advertising and invitations for multipeer connectivity for a MCNearbyServiceAdvertiser object.
MCNearbyServiceAdvertiserDelegate_ExtensionsExtension methods to the IMCNearbyServiceAdvertiserDelegate interface to support all the methods from the MCNearbyServiceAdvertiserDelegate protocol.
MCNearbyServiceAdvertiserInvitationHandlerThe delegate that serves as the invitation handler in calls to MCNearbyServiceAdvertiserDelegate.DidReceiveInvitationFromPeer.
MCNearbyServiceBrowserAllows programmatic browsing for devices advertising for multipeer connetivity.
MCNearbyServiceBrowserDelegateA delegate object that exposes peer-discovery events for a MCNearbyServiceBrowser object.
MCNearbyServiceBrowserDelegate_ExtensionsExtension methods to the IMCNearbyServiceBrowserDelegate interface to support all the methods from the MCNearbyServiceBrowserDelegate protocol.
MCPeerIDIdentifies a device in a multipeer connectivity network.
MCSessionRepresents a persistent connection between multiple devices.
MCSessionDelegateA delegate object whose functions relate to events in the MCSession life-cycle, such as connection status changes and data reception.
MCSessionDelegate_ExtensionsExtension methods to the IMCSessionDelegate interface to support all the methods from the MCSessionDelegate protocol.
MCSessionNearbyConnectionDataForPeerCompletionHandlerA delegate that serves as the completion handler for NearbyConnectionDataForPeer.
MCSessionSendDataModeAn enumeration whose values specify whether a message's delivery is guaranteed. Used with MCSession.SendData.
MCSessionStateAn enumeration whose values indicate the state of a MCSession. Used with MCSessionDelegate.DidChangeState.