So I noticed when sending data using MultipeerConnectivity I'm not sure exactly how I'm supposed to distinguish between an error or a declined invitation. For example I have Device Sender & Device Receiver.
1) Device Sender sends device Receiveran invitation using MCNearbyServiceBrowser's method -invitePeer:toSession:withContext:timeout:
2) Device Sender hasthe delegate set on the session used to send the invitation.
3) The delegate for the MCSession invitation waits for -session:peer:didChangeState: before sending the real meat.
-(void)session:(MCSession*)session peer:(MCPeerID*)peerID didChangeState:(MCSessionState)state
{
if (state == MCSessionStateConnecting)
{
}
else if (state == MCSessionStateNotConnected)
{
if (self.waitingOnReceiverToAcceptInvite)
{
NSLog(@"uh o, never got started abort...invitation was declined?");
[session disconnect];
}
else
{
//Not connected. Maybe we finished all our work already, maybe not...
//handle error in the completion handler of -sendResourceAtURL:withName:toPeer:withCompletionHandler:
//if we have one
}
}
else if (state == MCSessionStateConnected)
{
if (self.waitingOnReceiverToAcceptInvite)
{
self.waitingOnReceiverToAcceptInvite = NO;
[self beingSendingStuffToReciever];
}
}
}
So... the -beingSendingStuffToReciever method sends a resource using the session's sendResourceAtURL:withName:toPeer:withCompletionHandler:
So during testing, if the Receiver declines the invitation the Sender's session gets -session:peer:didChangeState: with a not connected state. If the waitingOnReceiverToAcceptInvite property is YES, I bail on the session and assume the invitation was declined. Why? Because I don't see any other way to detect if the Sender declined the invitation. But, during testing, I noticed that other reasons (like errors which seem to be abstracted away and inaccessible from the MultipeerConnectivity API) can cause the session delegate to get a -session:peer:didChangeState: message with a MCSessionStateNotConnected state while my waitingOnReceiverToAcceptInvite is YES.
So the peer is not connected to the session and I don't see a way to determine why. Was there some sort of network error and can I retry or did the Receiver just decline the invitation? How am I supposed to know? Is there some other API in this framework that I'm missing?
Thanks a lot