MonoTouch.MultipeerConnectivity.MCSession Class
Represents a persistent connection between multiple devices.

See Also: MCSession Members

Syntax

[MonoTouch.Foundation.Register("MCSession", true)]
[MonoTouch.ObjCRuntime.Availability(Introduced=MonoTouch.ObjCRuntime.Platform.iOS_7_0)]
public class MCSession : MonoTouch.Foundation.NSObject

Remarks

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

The MonoTouch.MultipeerConnectivity.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 MonoTouch.MultipeerConnectivity.MCAdvertiserAssistant or custom controller that uses a MonoTouch.MultipeerConnectivity.MCNearbyServiceAdvertiser. Similarly, browsing is managed by a MonoTouch.MultipeerConnectivity.UIViewController, either the stock MonoTouch.MultipeerConnectivity.MCBrowserViewController or a custom controller that uses a MonoTouch.MultipeerConnectivity.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 MonoTouch.MultipeerConnectivity.MCSession connects.

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

AdvertiserBrowserDiscussion
Create a new MonoTouch.MultipeerConnectivity.MCNearbyServiceAdvertiserDelegate and assign it to the MCNearbyServiceAdvertiser.Delegate property.Create a new MonoTouch.MultipeerConnectivity.MCNearbyServiceBrowserDelegate and assign it to MCNearbyServiceBrowser.Delegate property.Discovery and connection is taken care of by the delegate objects for the MonoTouch.MultipeerConnectivity.MCNearbyServiceAdvertiser and MonoTouch.MultipeerConnectivity.MCNearbyServiceBrowser.
The advertiser may instantiate a new MonoTouch.MultipeerConnectivity.MCSession now or wait until it receives an invitation.Instantiate a new MonoTouch.MultipeerConnectivity.MCSession.The browser should maintain a reference to a single MonoTouch.MultipeerConnectivity.MCSession object no matter how many peers ultimately connect.
MonoTouch.MultipeerConnectivity.MCNearbyServiceAdvertiser.StartAdvertisingPeerMonoTouch.MultipeerConnectivity.MCNearbyServiceBrowser.StartBrowsingForPeersAdvertiser and browser must use identical serviceType strings to identify their protocol / application. Peer IDs should be unique to each device.
The system will call MonoTouch.MultipeerConnectivity.MCNearbyServiceBrowserDelegate.FoundPeer, passing in a reference to the MonoTouch.MultipeerConnectivity.MCNearbyServiceBrowser. The application developer calls MonoTouch.MultipeerConnectivity.MCNearbyServiceBrowser.InvitePeer, passing in a reference to the previously-created MonoTouch.MultipeerConnectivity.MCSession.The callback is likely to occur on a background thread. If the application developer wishes to update the display, they must use MonoTouch.Foundation.NSObject.InvokeOnMainThread.
The system will call MonoTouch.MultipeerConnectivity.MCNearbyServiceAdvertiserDelegate.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 MonoTouch.MultipeerConnectivity.MCSession.The callback is likely to occur on a background thread. If the application developer wishes to update the display, they must use MonoTouch.Foundation.NSObject.InvokeOnMainThread.
Once the devices are connected, the MonoTouch.MultipeerConnectivity.MCSession objects can be used to transmit messages and data between devices.

Related content

Requirements

Namespace: MonoTouch.MultipeerConnectivity
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0