Search code examples
iphoneobjective-cmacosipadnsnetservice

NSNetService - how do I find out if it's a mac or iOS device?


Is there a way for me to find out if a device located over NSNetService is an iPhone, iPad or a Mac? The only solution I can think of right now is to connect to all of the ones found and ping them, and have each of them set up to ping back with that information. Would i be able to extend NSNetService on all of them to have "Device type" where for itself it would say? Or is there a simpler way?


Solution

  • NSNetService provides:

    - (BOOL)setTXTRecordData:(NSData *)recordData
    

    That I've used for something analogous to "out of band" data between clients (without actually having to connect to them). On the other end your NSNetServiceDelegate will get a callback via

    - (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData *)data
    

    with the same data.

    Indicating device type isn't exactly its intended use, but if you're looking for an alternative to establishing a connection I'm not sure there's any other way with NSNetService.