Disconnect individual peers from MCSession?

前端 未结 1 1642
你的背包
你的背包 2021-01-20 04:02

If I have an array of connected peers, let\'s say 3 (a->b, a->c, a->d) and I want to disconnect peer \"c\" only, what should I be doing?

I\'ve seen one response to a

相关标签:
1条回答
  • 2021-01-20 04:53

    Each peer-to-peer connection is represented by an instance of MCSession. So in your example, you will have 3 UNIQUE pointers to MCSession objects:

    MCSession *p1 = a->b
    MCSession *p2 = a->c
    MCSession *p3 = a->d
    

    so to disconnect peer c you will:

    [p2 disconnect]; // release the session
    p2 = nil; // release the resource
    

    Of course, you can store sessions in a mutable array and then do the same logic, but use the pointer from the array

    p2 = (MCSession *)[array objectAtIndex:1];
    [p2 disconnect];
    [array removeObjectAtIndex:1];
    
    0 讨论(0)
提交回复
热议问题