According to docs, MCSessionStateNotConnected may mean that
"... a neighboring peer rejected the invitation, the connection could not or the previously connected peer is no longer connected."
You are not saying in your question what will lead to the rejection of the invitation, but assuming that it is user-driven, one approach could be that your MCNearbyServiceAdvertiserDelegate automatically accepts the invitation, creating a new session for each peer, and then presents the user with the opportunity to accept or reject the connection. Your colleagues will not be considered truly in a session with each other until they receive a subsequent message indicating the user's decision:
So, in the MCNearbyServiceAdvertiserDelegate class, which you would accept, and then query the user:
- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData *)context invitationHandler:(void(^)(BOOL accept, MCSession *session))invitationHandler {
And then, when the user answered, you could have a method that sends a simple string in the form of NSData containing the status:
@property NSData *inviteAcceptedMsgData = [@"MPCInviteYES" dataUsingEncoding:NSUTF8StringEncoding]; @property NSData *inviteDeclinedMsgData = [@"MPCInviteNO" dataUsingEncoding:NSUTF8StringEncoding]; - (void)invitationFromPeerID:(MCPeerID *)peerID receivedResponse:(BOOL)accepted {
MCNearbyServiceBrowserDelegate will work in a similar way:
- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info {
The browser will then wait for a message from the invited partner to determine if the invitation was actually accepted:
- (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID {
You may already have a messaging system, but this is a simple implementation of the transfer state between connected peers. Regarding sending broadcast messages or displaying connected peers, _acceptedSessionPeerIDMap should be used as a true collection of peers.