为什么我的 MCSession 对等方会随机断开连接? [英] Why does my MCSession peer disconnect randomly?

查看:19
本文介绍了为什么我的 MCSession 对等方会随机断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MCNearbyServiceBrowser 和 MCNearbyServiceAdvertiser 将两个对等点加入一个 MCSession.我可以使用 MCSession 的 sendData 方法在它们之间发送数据.一切似乎都按预期工作,直到我随机(而不是由于我控制的任何事件)通过会话的 MCSessionDelegate didChangeState 处理程序接收到 MCSessionStateNotConnected.此外,MCSession 的 connectedPeers 数组不再有我的同行.

Im using MCNearbyServiceBrowser and MCNearbyServiceAdvertiser to join two peers to a MCSession. I am able to send data between them using MCSession's sendData method. All seems to be working as expected until I randomly (and not due to any event I control) receive a MCSessionStateNotConnected via the session's MCSessionDelegate didChangeState handler. Additionally, the MCSession's connectedPeers array no longer has my peers.

两个问题:为什么?以及如何防止 MCSession 断开连接?

Two questions: Why? and How do i keep the MCSession from disconnecting?

推荐答案

这是一个错误,我刚刚报告给 Apple.文档声称 didReceiveCertificate 回调是可选的,但事实并非如此.将此方法添加到您的 MCSessionDelegate:

This is a bug, which I just reported to Apple. The docs claim the didReceiveCertificate callback is optional, but it's not. Add this method to your MCSessionDelegate:

- (void) session:(MCSession *)session didReceiveCertificate:(NSArray *)certificate fromPeer:(MCPeerID *)peerID certificateHandler:(void (^)(BOOL accept))certificateHandler
 {
     certificateHandler(YES);
 }

应该停止随机断开连接.

The random disconnects should cease.

这篇关于为什么我的 MCSession 对等方会随机断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆