美文网首页
NSNetServicesErrorCode = "-72008

NSNetServicesErrorCode = "-72008

作者: 谁的青春不迷茫 | 来源:发表于2024-05-21 16:12 被阅读0次

环境: xcode15iOS14+
使用MultipeerConnectivityNSNetServiceBrowser时报错,错误信息如下:

Server did not publish: errorDict [{
    NSNetServicesErrorCode = "-72008";
    NSNetServicesErrorDomain = 10;
}].

解决方案
需要在info.plist加入

  1. NSLocalNetworkUsageDescription - 权限申请
  2. NSBonjourServices - 服务声明
<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>

注意
plist的NSBonjourServices,按照你的需求选择是否tcp和udp都有,
命名规则是_my-service._tcp_my-service._udp,
_my-service_tcp_udp_都不能删除,否则无效。

例如
如果你定义的服务是:

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

在代码调用是就要使用foobar

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

相关文章

网友评论

      本文标题:NSNetServicesErrorCode = "-72008

      本文链接:https://www.haomeiwen.com/subject/qojafjtx.html