11

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.

3 Answers 3

29

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

0
5

I fixed this issue by adding below code to Info.plist:

<key>NSBonjourServices</key>
<array>
    <string>_http._tcp.</string>
</array>
1
  • I used this for Chromecast. Then it told me what services it wanted to be listed.
    – Brian M
    Apr 2, 2021 at 13:23
1

@DDP, I come from your answer in GCDWebServer issue #525. The problem I meet is similar with yours. For me, I couldn't open home page when using real iPhone. The server is opened successfully in console but cannot connect it in browser.

I add the following keys as your answer showed, and change _my-service._tcp with what in GCDWebServer.

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

After this change, the issue is fixed. Thank you!

So this issue is related with the new permission of iOS 14 to find and connect to devices on your local network. Either granted or not granted this permission, I could access the web server, it is weird!

Though I'm curious about how you debug to find the root cause. For me, there is no any error/additional info showed in Xcode console, I have no clues about where is wrong.

1
  • 1
    Thanks yes I had the same story. I had set up multipeer connectivity which was newly failing, but only on iOS. The same code still worked fine on macOS. Googling had me reviewing 15 or more open tabs but the error code wasn't specifically helping. I tried the recommendations in the above forum thread and it worked. I probably should have already reviewed the WWDC video but had missed it.
    – DDP
    Dec 15, 2020 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.