NSNetServiceBrowser did not search with error -72008 on iOS 14
Asked Answered
S

3

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.

Soudan answered 7/12, 2020 at 21:59 Comment(0)
S
33

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

Soudan answered 7/12, 2020 at 21:59 Comment(0)
C
5

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

<key>NSBonjourServices</key>
<array>
    <string>_http._tcp.</string>
</array>
Chenay answered 17/3, 2021 at 7:13 Comment(1)
I used this for Chromecast. Then it told me what services it wanted to be listed.Biogeochemistry
O
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.

Oscillogram answered 14/12, 2020 at 12:41 Comment(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.Soudan

© 2022 - 2024 — McMap. All rights reserved.