8

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?

4

3 回答 3

1

您应该实现browser:didNotStartBrowsingForPeers:委托方法。如果调用它,NSError您收到的对象将帮助您诊断问题。

- (void)browser:(MCNearbyServiceBrowser *)browser didNotStartBrowsingForPeers:(NSError *)error
{
    NSLog( @"Unable to start browsing for peers. Error: %@", error );
}
于 2014-01-22T19:02:49.267 回答
1

确保一切都是财产。甚至是您为封装多点连接框架而创建的自定义类。

于 2015-03-20T17:50:24.370 回答
0

将同一会话传递给广告客户和浏览器。会话应该是全局的,并且应该尽可能长时间地运行。

于 2014-04-04T23:20:00.647 回答