所以,这是我的问题:我的 iOS 应用程序正在通过本地网络宣传 NSNetService,服务发现运行良好。我也知道我需要先解决我的服务,然后才能读取它的 TXTRecordData。在服务的 -didPublish 委托方法中,我确保我的 TXTRecordData 设置了 NSDictionary。到目前为止,一切都很好...
- (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);
}
如果调用 -netServiceDidResolveAdress 方法,则应用程序崩溃,因为 sender.TXTRecordData 为 nil。但为什么它是零?
提前感谢您的任何回答:D