MultipeerConnectivityFramework not working due to new privacy setting

I was using MCFramework with no problem but now that Im building with Xcode 12 and iOS 14, 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. 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). Also the method browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) is marked as optional but If I don't implement it my app crashes.

Replies

I'm experiencing exactly the same problem. Would love to hear any advices on this from Apple team

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, the NSNetServicesErrorCode is associated with Bonjour and is letting you know that NSNetService, is having issues advertising your Bonjour service for your MultiPeer API.

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).

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.

Code Block xml
<key>NSBonjourServices</key>
<array>
<string>_multipeertest._tcp</string>
</array>


Also the method browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) is marked as optional but If I don't implement it my app crashes.

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.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Matt

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

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.

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>

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?

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.

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.

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.



Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com