问题描述
设置多点连接(使用 Bonjour)也会触发相同的错误.我用于启动 Bonjour 浏览和 Multipeer Connectivity 的代码是从 Apple 示例代码修改而来的,并且在 iOS 13 下运行良好.
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.
推荐答案
您需要在 Info.plist 中添加以下键:NSLocalNetworkUsageDescription 和 NSBonjourServices.例如
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>
确保为您的服务名称正确命名了 my-service.例如.如果您正在为 foobar" 服务设置 MPC,您可能有
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)
所以你会使用
<string>_foobar._tcp</string>
<string>_foobar._udp</string>
(您的实现中可能不需要 TCP 和 UDP.)
(You might not require both TCP and UDP in your implementation.)
参见 https://developer.apple.com/videos/play/wwdc2020/10110/
和https://developer.apple.com/forums/thread/653316
这篇关于NSNetServiceBrowser 在 iOS 14 上没有搜索错误 -72008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!