Search code examples
iosnetworkingbonjourmultipeer-connectivity

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.


Solution

  • 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