【问题标题】:invitePeer timeout in Multipeer Connectivity iOS 7Multipeer Connectivity iOS 7中的invitePeer超时
【发布时间】:2013-10-14 18:20:37
【问题描述】:

我正在使用此方法请求附近的设备加入会话: 当我这样做时,我也会开始旋转指示器

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

是否有在超时时刻调用的方法?如果其他设备超出范围怎么办?

编辑:

我注意到这个状态永远不会被调用:

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

【问题讨论】:

    标签: ios multipeer-connectivity


    【解决方案1】:

    如果浏览器端超时,您需要注意 MCSessionStateNotConnected 状态。我做这样的事情:

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

    使用 dispatch_sync 立即弹出警报。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-04
        • 1970-01-01
        • 2016-06-10
        • 1970-01-01
        • 2016-01-24
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        相关资源
        最近更新 更多