Skip to content

Instantly share code, notes, and snippets.

@mikebluestein
Created March 18, 2012 18:18
Show Gist options
  • Save mikebluestein/2079186 to your computer and use it in GitHub Desktop.
Save mikebluestein/2079186 to your computer and use it in GitHub Desktop.
Add a TXTRecord using Bonjour and MonoTouch
NetDelegate _netDel;
NSNetService _ns;
void InitNetService ()
{
_ns = new NSNetService ("", "_testservice._tcp", UIDevice.CurrentDevice.Name, 9999);
_netDel = new NetDelegate ();
_ns.Delegate = _netDel;
// add TXTRecordData
var s = new NSString ("Bonjour from MonoTouch");
var dictionary = NSDictionary.FromObjectAndKey (s, new NSString ("myKey"));
var record = NSNetService.DataFromTxtRecord (dictionary);
_ns.TxtRecordData = record;
_ns.Publish ();
}
// Run this command in Terminal to see if it was added ok:
// dns-sd -Z _testservice._tcp local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment