i am using NetServiceBrowser for descovering bonjour services but my app is calling only netBrowserServiceWillSearch delegate method and keep on searching the Bonjour service without ever finding or stoping.
class BonjourDiscovery : NetServiceBrowserDelegate, NetServiceDelegate
{
let serviceBrowser = NetServiceBrowser()
@objc func ListOfPrinter(){
serviceBrowser.delegate = self
serviceBrowser.searchForServices(ofType: "_printer._tcp", inDomain: "")
}
func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
print("---------didFind: \(service.name)")
}
func netServiceBrowserDidStopSearch(_ browser: NetServiceBrowser) {
print(#function)
}
func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) {
print(#function)
}
func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) {
print(#function)
}
func netServiceBrowserWillSearch(_ browser: NetServiceBrowser) {
print(#function)
}
}
info.plist -:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocalNetworkUsageDescription</key>
<string>Looking for local tcp Bonjour service</string>
<key>NSBonjourServices</key>
<array>
<string>_printer._tcp</string>
</array>
</dict>
</plist>
i have tried diffrent things whatever i found on apple forum or stackOverFlow like adding local in inDomain ,replacing _printer._tcp with _printer._tcp. ,but nothing works so far