Multipeer Connectivity: getting an invitation accepted (using built-in browser VC)

后端 未结 3 1238
死守一世寂寞
死守一世寂寞 2021-01-12 18:07

I\'m trying to follow the WWDC talk to learn about the MultipeerConnectivity framework. After many false starts, the browser(s) show the peers, and invitations get issued.

3条回答
  •  无人共我
    2021-01-12 18:35

    I was having the same issue and it turned out i was using the same session for both the browser and the advertiser. split up the sessions but make sure serviceType is the same and it'll work like a charm

    - (void) setUpMultipeer{
        //  Setup Peer ID
        self.myPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].name];
    
        //  Setup Sessions
        self.advertiseSession = [[MCSession alloc] initWithPeer:self.myPeerID];
        self.advertiseSession.delegate = self;
    
        self.browserSession = [[MCSession alloc] initWithPeer:self.myPeerID];
        self.browserSession.delegate = self;
    
    
        //  Setup BrowserVC
        self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:@"SERVICE_TYPE" session:self.browserSession];
        self.browserVC.delegate = self;
    
        //  Setup Advertiser
        self.advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"SERVICE_TYPE" discoveryInfo:nil session:self.advertiseSession];
        [self.advertiser start];
    }
    

提交回复
热议问题