NSNetServiceBrowser did not search with error -72008 on iOS 14

情到浓时终转凉″ 提交于 2021-02-20 04:40:07

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/65190065/nsnetservicebrowser-did-not-search-with-error-72008-on-ios-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!