MultipeerConnectivityFramework not working due to new privacy setting
Yes, the NSNetServicesErrorCode is associated with Bonjour and is letting you know that NSNetService, is having issues advertising your Bonjour service for your MultiPeer API.when I try to start advertising Im getting a 72008 NSNetServicesErrorCode. I search the error and it says that Im missing the Local Network Usage Description.
Yes, I recently ran into this on another issue I was researching and the issue came down to how the Bonjour service is formatted in the plist. For example, if your service is: "multipeertest, " you will need to specify your NSBonjourServices as _multipeertest._tcp in your Info.plist.I've already added the Local Network Usage Description in my plist and I don't know what should I add in Bonjour Services key (Documentation is not clear when using Multipeer framework).
Code Block xml <key>NSBonjourServices</key> <array> <string>_multipeertest._tcp</string> </array>
I have also seen this happen and would recommend adding the delegate method for two reasons; first, it can be helpful when needing to let users know an error took place. Second, in the case where this method is triggered due to local network privacy issues this could be a method to let users know that they need to check their local network privacy settings.Also the method browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) is marked as optional but If I don't implement it my app crashes.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
This new privacy setting is really creating major headaches.
First the Bonjour services in the info.plist is not very well documented. I think I figured it out by setting "{service}.tcp where {service} must match the serviceType in MCNearbyServiceAdvertiser(peer: , discoveryInfo: , serviceType: ). It seems to be working for me.
browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) is called when the Bonjour service is not properly set, however it does not seem to be called when the local network access is denied. Actually I could not find any method called when access is denied. Is there one?
Then the localization of the NSLocalNetworkUsageDescription does not seem to work. The user only gets what's setup in the info.plist, or the default Apple message when nothing is setup.
Finally on the simulator the local network access permission does not seem to be implemented at all. It works as it used with iOS13 making the testing process more difficult.
The most important issue is to at least be able to know when the permission is denied otherwise we are completely blind. Very hard to design a great user experience.
Hope someone has figured out some of these issues.
Thanks
Right, that is why I wanted to mention the format of _multipeertest._tcp as this is something I ran into myself while doing Multipeer Connectivity debugging. As for the documentation side of this, I believe the NSBonjourServices documentation does now contain the correct format: <https://developer.apple.com/documentation/bundleresources/information_property_list/nsbonjourservices?language=objc>First the Bonjour services in the info.plist is not very well documented. I think I
figured it out by setting "{service}.tcp where {service} must match the serviceType in
MCNearbyServiceAdvertiser(peer: , discoveryInfo: , serviceType: ). It seems to be
working for me.
This is a good data point, thank you for bringing it up. If the local network access is denied, and you are not seeing this delegate method get hit that is something I need to go retest to confirm my previous statement. It does sound like you are getting 72008 NSNetServicesErrorCode in the console though, so from a debugging standpoint this should provide some clues there at least.browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) is called when the Bonjour service is not properly set, however it does not seem to be called when the local network access is denied. Actually I could not find any method called when access is denied. Is there one?
I would make sure you are testing local network access on a real device. The simulator does use the macOS network stack and local network access is not enforced there, so there could be some conflicts here that are not showing you a true result.Finally on the simulator the local network access permission does not seem to be implemented at all. It works as it used with iOS13 making the testing process more difficult.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com