public void initializeMCServices() { myPeerId = new MCPeerID(UIDevice.CurrentDevice.Name); MyAdvertiserDelegate myAdvertiserDelegate = new MyAdvertiserDelegate(this); MyBrowserDelegate myBrowserDelegate = new MyBrowserDelegate(this); MySessionDelegate mySessionDelegate = new MySessionDelegate(this); var emptyDict = new NSDictionary(); MCNearbyServiceAdvertiser serviceAdvertiser = new MCNearbyServiceAdvertiser(myPeerId, emptyDict, serviceTypeString); serviceAdvertiser.Delegate = myAdvertiserDelegate; serviceAdvertiser.StartAdvertisingPeer(); MCNearbyServiceBrowser serviceBrowser = new MCNearbyServiceBrowser(myPeerId, serviceTypeString); serviceBrowser.Delegate = myBrowserDelegate; serviceBrowser.StartBrowsingForPeers(); session = new MCSession(myPeerId); session.Delegate = mySessionDelegate; sendPeerToPeerData(myPeerId.DisplayName); }
/// <summary> /// For use when acting as game server /// </summary> public void StartAdvertising() { if (this.serviceAdvertiser == null) { var discoveryInfo = NSDictionary.FromObjectAndKey(new NSString(appIdentifier), new NSString(XamarinShotGameAttribute.AppIdentifier)); if (this.location != null) { discoveryInfo[LocationKey] = new NSString(this.location.Identifier.ToString()); } var advertiser = new MCNearbyServiceAdvertiser(this.myself.PeerId, discoveryInfo, XamarinShotGameService.PlayerService); advertiser.Delegate = this; advertiser.StartAdvertisingPeer(); this.serviceAdvertiser = advertiser; } }