Multipeer Connectivity :List all nearby sessions

815 views Asked by At

I'am working on Multipeer connectivity in ios 7 and its working nice.But what i need is,when i press a search button it need to display all nearby sessions(not nearby devices).Is there any possible solution for this. Please Help!!!

2

There are 2 answers

0
ChrisH On BEST ANSWER

You don't say why you want to pass MCSession objects between peers, but once you have two connected peers, you can pass any object that conforms to the NSCoding protocol between the peers using one of the MCSession data sending methods such as

- (BOOL)sendData:(NSData *)data toPeers:(NSArray *)peerIDs withMode:(MCSessionSendDataMode)mode error:(NSError **)error

However MCSession doesn't conform to NSCoding, so you'd be better off sending metadata from the MCSession between peers. So if Peer A and Peer B were connected, and Peer A wanted to know which other peers Peer B was connected to, Peer B could send an array of NSString objects listing the displayName of each peer.

But even if you did that, if Peer A hasn't discovered (or been discovered by) Peer B's connected peers, you're not going to be able to communicate with them anyway. The fact that you're looking for ways to send MCSession objects between peers means there's probably a better way to tackle what you're trying to achieve.

tl;dr

MCSession handles connections between peers. The peers would need to be connected to share their MCSession objects in the first place.

0
dev gr On

You can not advertise an MCSession, instead use multiple MCNearbyServiceBrowser objects and MCNearbyServiceAdvertiser objects to browse and advertise multiple service types.

When you initilize an MCNearbyServiceAdvertiser using initWithPeer:discoveryInfo:serviceType: put your service name(service type) in discover info so that when you peer get found by an MCNearbyServiceBrowser (browsing for same service type) inside MCNearbyServiceBrowserDelegate's browser:foundPeer:withDiscoveryInfo: you can determine the service type and display in UI.

In this way same peer will appear multiple times with different service types. You can choose desired service type to proceed with. I adivse you to use a separate MCSession for each service type. For doing this you need to maintain all the browsers and advertisers objects carefully.

Hope it helps.