NSNetServiceBrowser 在 iOS 14 上未搜索并出现错误 -72008

2023-12-25

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


您需要将以下键添加到 Info.plist:NSLocalNetworkUsageDescription and NSBonjour服务. 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>

确保 my-service 已根据您的服务名称正确命名。例如。如果您正在为"foobar"服务,你可能有

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

所以你会使用

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

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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NSNetServiceBrowser 在 iOS 14 上未搜索并出现错误 -72008 的相关文章

随机推荐