NSNetServiceBrowser在iOS14上没有搜索错误-72008

设置多点连接(使用 Bonjour)也会触发相同的错误。我用于启动 Bonjour 浏览和 Multipeer Connectivity 的代码是从 Apple 示例代码修改而来的,并且在 iOS 13 下运行良好。

回答

您需要将以下键添加到 Info.plist:
NSLocalNetworkUsageDescriptionNSBonjourServices。例如

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

确保为您的服务名称正确命名了 my-service。例如,如果您正在为“foobar”服务设置 MPC ,您可能有

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

所以你会使用

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

(您的实现中可能不需要 TCP 和 UDP。)

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

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


以上是NSNetServiceBrowser在iOS14上没有搜索错误-72008的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>