首页 > 解决方案 > 多点连接对等点有时无法在完美的网络条件下重新连接

问题描述

当使用 Multipeer Connectivity 框架通过“每个设备宣传服务 + 每个人邀请每个人”实现连接多个 iPhone/iPad 时,我有时会看到即使在完美的 Wi-Fi 网络条件下也无法连接的设备。

这是一个可用于重现该问题的示例项目:
https ://github.com/ralfebert/ConnectedColors/

处理 Multipeer Connectivity 会话的代码在这里:
https ://github.com/ralfebert/ConnectedColors/blob/main/ConnectedColors/ColorMultipeerSession.swift

我向 Apple 报告了以下关于此的 FB 报告,假设这是一个错误,而不是对框架/预期行为的错误使用。

问题:这确实是 Multipeer Connectivity 框架中的一个错误,还是我错误地使用了该框架?如果是错误,是否有可用于确保设备始终在良好网络条件下连接的解决方法?


FB9703076:多点连接对等点有时无法在完美的网络条件下重新连接

当使用 Multipeer Connectivity 框架通过“每个设备宣传服务 + 每个人邀请每个人”实现连接多个 iPhone/iPad 时,我有时会看到即使在完美的 Wi-Fi 网络条件下设备也无法连接。

重现步骤:

该应用程序尝试每 5 秒重新邀请已知但未连接的对等方。有时这有助于恢复此类故障,但通常它会完全卡住。

以下是 3 台设备发生此类连接失败的视频: https ://www.youtube.com/watch?v=MDg2BlN65R4

在这些情况下,您可以在日志中看到失败的重新邀请尝试以及以下错误:

2021-10-14 12:33:01.808847+0200 ConnectedColors[1505:832300] [connection] nw_endpoint_handler_set_adaptive_read_handler [C43 fe80::60:594d:64d9:7d95%en0.49772 ready socket-flow (satisfied (Path is satisfied), viable, interface: en0, scoped, ipv4, ipv6, dns)] unregister notification for read_timeout failed
2021-10-14 12:33:01.809123+0200 ConnectedColors[1505:832300] [connection] nw_endpoint_handler_set_adaptive_write_handler [C43 fe80::60:594d:64d9:7d95%en0.49772 ready socket-flow (satisfied (Path is satisfied), viable, interface: en0, scoped, ipv4, ipv6, dns)] unregister notification for write_timeout failed
2021-10-14 12:33:01.845341+0200 ConnectedColors[1505:831238] didReceiveInvitationFromPeer <MCPeerID: 0x283678110 DisplayName = iPad>

相关资源

示例项目来自我关于使用 Multipeer Connectivity 框架的介绍性文章: https ://www.ralfebert.de/ios/tutorials/multipeer-connectivity/

ConnectedColors 项目的设置与“创建协作会话”示例项目中的设置非常相似:
https ://developer.apple.com/documentation/arkit/creating_a_collaborative_session

标签: iosmultipeer-connectivity

解决方案


推荐阅读