我有解决问题NSNetService
。找到该服务NSNetService
时,我已成功解决。NSNetServiceBrowser
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing{
if (![self.services containsObject:aNetService]) {
[aNetService setDelegate:self];
[aNetService resolveWithTimeout:5.0];
}
}
那么这个方法就被成功调用了
-(void)netServiceDidResolveAddress:(NSNetService *)sender{
NSArray *addresses = [ns addresses];
NSDictionary* dict = [NSNetService dictionaryFromTXTRecordData:[sender TXTRecordData]];
// Here both values are ok
}
但我想将 NSNetService 解析到服务器端以获取发布该服务的 IP 地址。
-(void)netServiceDidPublish:(NSNetService *)ns{
[ns setDelegate:self];
[ns resolveWithTimeout:5.0];
}
但这里这个方法没有调用。
-(void)netServiceDidResolveAddress:(NSNetService *)sender{
}
但是我这样做了
-(void)netServiceDidPublish:(NSNetService *)ns
{
NSArray *addresses = [ns addresses]; // this gives null
// this also gives null
NSDictionary* dict = [NSNetService dictionaryFromTXTRecordData:[sender TXTRecordData]];
}
但价值观是null
。
如果可能,请帮助我。任何帮助将不胜感激。提前致谢。