Domanda

I'm using the Multipeer Connectivity Framework to transfer files between devices. I'm using the standard MCAdvertiserAssistant and MCBrowserViewController to connect the devices. On the first try from device A to device B things work fine. Same things on the first transfer from device B to device A.

If you try either direction again, after MCBrowserViewController presents its dialog to choose a peer and you select one, the popup to accept the request on the other device never appears. No error messages, no calls to delegate methods - just nothing. Has anyone come across this and any ideas?

È stato utile?

Soluzione

I had the same problem and solved it with initiating all the necessary components every time I start advertising or browsing for peers. It isn't the cleanest solution but in my case it works 100%.

The code below is how I implemented it, so this is without the build-in ViewController provided by Apple.

Please be aware that [session disconnect] is an async method which sometimes take a few seconds to complete.

- (void)startBrowsing
{
    // Initiate new advertiser
    isAdvertising = YES;

    _peerID = [[MCPeerID alloc] initWithDisplayName:@"Wallet"];
    _session = [[MCSession alloc] initWithPeer:_peerID];
    _session.delegate = self;

    _advertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:_peerID discoveryInfo:nil serviceType:@"made2pay"];
    _advertiser.delegate = self;

    // Start advertiser
    [_advertiser startAdvertisingPeer];
}

- (void)stopBrowsing
{
    [_advertiser stopAdvertisingPeer];
    [_session disconnect];
    _session    = nil;
    _peerID     = nil;
    _advertiser = nil;

    isAdvertising = NO;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top