简体   繁体   中英

invitePeer timeout in Multipeer Connectivity iOS 7

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);
}

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.

使用具有匹配超时参数的计时器间隔的计时器可能是更好的主意。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM