Why does my MCSession peer disconnect randomly?

前端 未结 5 1219
我寻月下人不归
我寻月下人不归 2020-11-29 18:36

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

5条回答
  •  醉话见心
    2020-11-29 19:25

    I was disconnecting immediately after I accepted the connection request. Observing the state, I saw it change from MCSessionStateConnected to MCSessionStateNotConnected.

    I am creating my sessions with:

    [[MCSession alloc] initWithPeer:peerID]
    

    NOT the instantiation method dealing with security certificates:

     - (instancetype)initWithPeer:(MCPeerID *)myPeerID securityIdentity:(NSArray *)identity encryptionPreference:(MCEncryptionPreference)encryptionPreference 
    

    Based on Andrew's tip above, I added the delegate method

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

    and the disconnects stopped.

提交回复
热议问题