My app has to find a certain bonjour service on the local network and my code works fine for iOS 12/13 as well as macOS Big Sur and Catalina.
The exact same code fails on iOS and iPadOS 14 with this error:
["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000]
Which I have looked into and -72000 is an "Unknown error".
I am using NetServiceBrowser to find the service and here is my code:
I have no idea what could be causing the error and have tried enabling networking permissions and capabilities but have not been able to stop the error from occurring.
Thanks.
The exact same code fails on iOS and iPadOS 14 with this error:
["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000]
Which I have looked into and -72000 is an "Unknown error".
I am using NetServiceBrowser to find the service and here is my code:
Code Block class Bonjour: NSObject { var discovered: [DiscoveredInstance] = [] let bonjourBrowser = NetServiceBrowser() var discoveredService: NetService? override init() { super.init() bonjourBrowser.delegate = self startDiscovery() } func startDiscovery() { self.bonjourBrowser.searchForServices(ofType: "_some-service._tcp.", inDomain: "local") } } extension Bonjour: NetServiceBrowserDelegate, NetServiceDelegate { func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { discoveredService = service discoveredService?.delegate = self discoveredService?.resolve(withTimeout: 3) } func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String : NSNumber]) { print(errorDict) } func netServiceBrowser(_ browser: NetServiceBrowser, didRemove service: NetService, moreComing: Bool) { self.discovered.removeAll { $0.name == service.name } } func netServiceDidResolveAddress(_ sender: NetService) { if let data = sender.txtRecordData() { let dict = NetService.dictionary(fromTXTRecord: data) /// do stuff with txtRecord dict here and then add to discovered array. discoveredService = nil } } }
I have no idea what could be causing the error and have tried enabling networking permissions and capabilities but have not been able to stop the error from occurring.
Thanks.
I tried this out as well and received the same error on iOS 14 while using Bonjour to browse for a local network.
Setting the usage description and Bonjour service I am browsing for in the info.plist resolve this issue:
For more on this checkout this year's WWDC Video on Support local network privacy in your app.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Note: that at the time of writing this these APIs are still in beta so please continue to review as the public release date draws near.
Setting the usage description and Bonjour service I am browsing for in the info.plist resolve this issue:
Code Block xml <key>NSLocalNetworkUsageDescription</key> <string>Looking for local tcp Bonjour service</string> <key>NSBonjourServices</key> <array> <string>_some-service._tcp</string> </array>
For more on this checkout this year's WWDC Video on Support local network privacy in your app.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Note: that at the time of writing this these APIs are still in beta so please continue to review as the public release date draws near.