CocoaDev

Edit AllPages

In my application I wanted to show the proper machine icon for the networked machines on my lan that have bonjour records. it turns out it was one week worth or research. and a lot of people involved in the mailing lists helped me out with this.

First: to retrive the computer model from the network you have to monitor the TXTRecord of the bonjour advertised computer you are interested in.

-(void) monitor:(HostDefinition *) host{

		bonjourMonitor = [[NSNetService alloc]initWithDomain:@"local." type:@"_device-info._tcp" name:@"yourHostNameHere"];
		[bonjourMonitor setDelegate:self];
		[bonjourMonitor startMonitoring]; //----------------------------------------------------------------------------- // this is the needed delegate function - (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData *)data{ NSLog(@"%@", [[[NSString alloc] initWithData:[[NSNetService dictionaryFromTXTRecordData:data] valueForKey:@"model"] encoding:NSUTF8StringEncoding]autorelease]; }

Obviously you want to retain that model name and do something with it.

(linux can broadcast bonjour device-info with avahi)

Now to get the proper icon for this particular model of computer i’ve concocted this class function.

//—————————————————————————– // Returns the Icon for the ModelCode published by bonjour. // if the modelCode can not be associated to an icon the default Mac icon is returned.

//—————————————————————————– // returns the default Mac machine icon.

Have fun.

Sandro Noel.

you can send comments and changes to sandro(dot)noel(At)mac(DOT)com