Multipeer Connectivity Framework - Lost Peer stays in Session

后端 未结 5 586
鱼传尺愫
鱼传尺愫 2020-12-23 15:36

I wonder if this Multipeer Connectivity framework is ready for use in the real world, given all the bugs that have been encountered by the community. I think I\'m setting it

5条回答
  •  时光说笑
    2020-12-23 16:10

    I couldn't get the accepted answer to ever work, so what i did instead is have a timer that would fire to reset the connection when the browser would report not connected and there were no other connected peers.

    -(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{
    
    //DebugLog(@"session didChangeState: %ld",state);
    
    if(resetTimer != nil){
        [resetTimer invalidate];
        resetTimer = nil;
    }
    
    if(state == MCSessionStateNotConnected){
    
        [session disconnect];
        [peerSessions removeObjectForKey:peerID.displayName];
        [self removeGuidyPeerWithPeerID:peerID];
        //DebugLog(@"removing all guides from peer %@",peerID);
    
        if([localSession connectedPeers].count == 0){
    
            DebugLog(@"nothing found... maybe restart in 3 seconds");
            dispatch_async(dispatch_get_main_queue(), ^{
                resetTimer = [NSTimer
                          scheduledTimerWithTimeInterval:3.0
                          target:self selector:@selector(onResetTimer:)
                          userInfo:nil
                          repeats:NO];
                }
            );
        }
    }
    ...
    

    }

提交回复
热议问题