Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Advertisers Found When Using MCNearbyServiceBrowser

I have a MultipeerService class which is used to start advertising and browsing sessions. For some reason I am not sure why I am not able to see any advertisers.

MultipeerService.m

-(void) startAdvertising
{
    NSString *name = [[UIDevice currentDevice] name];

    MCPeerID *peerId = [[MCPeerID alloc] initWithDisplayName:name];
    self.session = [[MCSession alloc] initWithPeer:peerId];
    self.session.delegate = self;

    self.advertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:peerId discoveryInfo:nil serviceType:kServiceType];
    self.advertiser.delegate = self;

    [self.advertiser startAdvertisingPeer];
}

-(void) startBrowsing
{
    NSString *name = [[UIDevice currentDevice] name];

    MCPeerID *peerId = [[MCPeerID alloc] initWithDisplayName:name];
    self.session = [[MCSession alloc] initWithPeer:peerId];
    self.session.delegate = self;

    self.browser = [[MCNearbyServiceBrowser alloc] initWithPeer:peerId serviceType:kServiceType];
    self.browser.delegate = self;

    [self.browser startBrowsingForPeers];
}

I start the advertiser like the following:

 _multipeerConnectivityService = [[MultipeerConnectivityService alloc] init];
[_multipeerConnectivityService startAdvertising];

I create a new instance of multipeerConnectivityService for browsing and invoke the startBrowsing method.

When I check in the foundPeer method in the multipeerConnectivityService I see nothing invoked. What am I doing wrong?

like image 954
john doe Avatar asked Dec 12 '13 17:12

john doe


2 Answers

You should implement the browser:didNotStartBrowsingForPeers: delegate method. If it is invoked, the NSError object you receive will help you diagnose the problem.

- (void)browser:(MCNearbyServiceBrowser *)browser didNotStartBrowsingForPeers:(NSError *)error
{
    NSLog( @"Unable to start browsing for peers. Error: %@", error );
}
like image 159
Pascal Bourque Avatar answered Oct 20 '22 09:10

Pascal Bourque


Make sure everything is a property. Even the custom classes that you made for encapsulating the multipeer connectivity framework.

like image 1
kylesyoon Avatar answered Oct 20 '22 10:10

kylesyoon