Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSNetServiceBrowser did not search with error -72008 on iOS 14

The same error is also triggered setting up Multipeer Connectivity (which uses Bonjour). The code I was using for initiating Bonjour browsing and Multipeer Connectivity was modified from the Apple sample code and worked fine under iOS 13.

like image 756
DDP Avatar asked Dec 07 '20 21:12

DDP


1 Answers

You need to add the following keys to the Info.plist: NSLocalNetworkUsageDescription and NSBonjourServices. E.g.

<key>NSLocalNetworkUsageDescription</key>
<string>Reason for using Bonjour that the user can understand</string>
<key>NSBonjourServices</key>
<array>
    <string>_my-service._tcp</string>
    <string>_my-service._udp</string>
</array>

Ensure that my-service is correctly named for your service name. E.g. if your are setting up MPC for a "foobar" service, you might have

mpcAdvertiserAssistant = MCAdvertiserAssistant(serviceType: "foobar", discoveryInfo: discoveryInfoDict, session: mpcSession)

and so you would use

<string>_foobar._tcp</string>
<string>_foobar._udp</string>

(You might not require both TCP and UDP in your implementation.)

See https://developer.apple.com/videos/play/wwdc2020/10110/

and https://developer.apple.com/forums/thread/653316

like image 170
DDP Avatar answered Sep 20 '22 05:09

DDP