So, here is my problem: My iOS app is advertising an NSNetService over the local network, service discovery is working good. I also know that I need to resolve my service before I am able to read it's TXTRecordData. In the service's -didPublish delegate method I made sure that my TXTRecordData is set up with an NSDictionary. So far, so good...
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
didFindService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing
{
if (!self.netServicesForResolution)
self.netServicesForResolution = [[NSMutableArray alloc] init];
NSLog(@"serviceBrowser found service: %@, with TXTRecordData: %@",
aNetService, aNetService.TXTRecordData);
[self.netServicesForResolution addObject:aNetService];
if (!moreComing) [self resolveNetServicesInArray];
}
- (void)resolveNetServicesInArray
{
for (NSNetService *service in self.netServicesForResolution) {
service.delegate = self;
[service resolveWithTimeout:5];
}
}
- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
[self.netServicesForResolution removeObject:sender];
NSString *dataDict = [NSKeyedUnarchiver unarchiveObjectWithData:sender.TXTRecordData];
NSLog(@"freshly resolved netService has TXTRecordData: %@", dataDict);
}
If the -netServiceDidResolveAdress method gets called the app crashes because sender.TXTRecordData is nil. But why is it nil?
Thanks in advance for any of your answers :D
I can't speak to why TXTRecordData is nil, but you should be using +[NSNetService dictionaryFromTXTRecordData:] to get a NSDictionary instead of NSKeyedUnarchiver to get a NSString.