I'm using the mutlipeer connectivity framework for the first time, and I want programmatic ( not with the assistant classes) control.
Everything is working exactly as described when I run my code on two separate devices up until the point when the 'advertiser' receives the delegate callback:
The browsing client's delegate callback is called when it discovers the advertiser:
-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info{
[[[UIAlertView alloc] initWithTitle:@"Peer Found" message:peerID.displayName delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//connect to the discovered peer.
[_browser invitePeer:peerID toSession:_session withContext:nil timeout:30.0];
[_browser stopBrowsingForPeers];
}
Then the advertising client's delegate callback is called when it receives the invite:
-(void)advertiser:(MCNearbyServiceAdvertiser *)advertiser didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData *)context invitationHandler:(void (^)(BOOL, MCSession *))invitationHandler{
//when my code runs, everything looks correct here.
//eg. peerID is definitely my 'browser' client's display name etc.
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//using a simple version for testing... accept all invites.
invitationHandler(YES, _session);
//stop advertising now.
[_advertiser stopAdvertisingPeer];
}
After 'invitationHandler(YES, _session)' is called, it seems like the connection is never established between the 'browsing' client and the 'advertising' client.
I don't ever receive any delegate callbacks (once or twice I received a MCSessionStateNotConnected ) on the MCSession objects on either client device. I would have thought I would have received the MCSession delegate callback:
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state;
Am I missing something? Has anyone else come across this issue?