Question

I am using this method to ask a nearby device to join the session: When I do it I also start spinning an indicator

[browser invitePeer:key
          toSession:session
        withContext:nil
            timeout:30];

Is there a method called in the moment of timeout? what if the other device goes out of range?

EDIT:

I notice that this state is never called:

if (state == MCSessionStateConnecting) {
    NSLog(@"CONNECTING %@", peerID);
}
Was it helpful?

Solution

in case of timeouts on the browser side, you need to watch for the MCSessionStateNotConnected state. i do something like this:

- (void)session:(MCSession *)session
           peer:(MCPeerID *)peerID
 didChangeState:(MCSessionState)state 
{
     if (state == MCSessionStateNotConnected) 
     {
          if (self.isWaitingForInvitation) 
          {
                UIAlertView *alertView = [[UIAlertView alloc]
                            initWithTitle:NSLocalizedString(@"ERROR_TITLE", nil)
                            message:NSLocalizedString(@"ERROR_TEXT", nil)
                            delegate:self
                            cancelButtonTitle:NSLocalizedString(@"NO", @"Não")
                            otherButtonTitles:NSLocalizedString(@"YES", @"Sim"),
                                                                     nil];
                dispatch_sync(dispatch_get_main_queue(), ^{
                    [alertView show];
                });
                self.isWaitingForInvitation = NO;
         }
}

use the dispatch_sync to make the alert popup right away.

OTHER TIPS

Using a timer with a timer interval matching timeout parameter could be better idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top