问题描述
我使用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对等端会随机断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!