I am doing one application. In that I am publishing the service using NsNetservice
and browse using NSNetserviceBrowser
. But sometimes service publish the services successfully, but browser not able to find that service using didFindservice
delegate method. Only netServiceBrowserWillSearch
is firing and didNotsearch
delegate method is also not firing. And if I restart the devices then it's working correctly.
Please help me how to resolve this problem.Code for browser and service please check below
Browser:
self.browser = [[NSNetServiceBrowser alloc] init];
self.browser.includesPeerToPeer = YES;
[self.browser setDelegate:self];
[self.browser searchForServicesOfType:[NSString stringWithFormat:@"%@%@._tcp.",serviceName,Name] inDomain:@""];
Service:
self.netService = [[NSNetService alloc] initWithDomain:@"" type:[NSString stringWithFormat:@"%@%@._tcp.",serviceName,Name] name:Name port:randomPortNumber];
self.netService.includesPeerToPeer = YES;
[self.netService setDelegate:self];
[self.netService scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.netService publishWithOptions:NSNetServiceListenForConnections];