IOS7 Multipeer Connectivity Creating custom nearby browser list using advertiser's discovery Info
I’m using Multipeer Connectivity Framework in IOS7 to make a chatting application. And I’m using the built-in MCBrowserViewController to display a list of nearby peers.
I’d like to include the advertiser’s profile info in the nearby peer list. So that browsers see a list that contains and image and some data about the nearby peers.
I think it can be accomplished by passing data through discoveryInfo when the advertiser is initialized. I pass the discoveryInfo data in like this:
// create Discovery Info NSArray *objects=[[NSArray alloc] initWithObjects:@"datguy",@"28", nil]; NSArray *keys = [[NSArray alloc] initWithObjects:@"Name",@"Age", nil]; self.dictionaryInfo = [[NSDictionary alloc] initWithObjects:objects forKeys:keys]; // Setup Advertiser self.advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"txt_msg_service" discoveryInfo:self.dictionaryInfo session:self.advertiseSession]; [self.advertiser start];
But is there any way to create a custom MCBrowserViewController that displays the discoveryInfo on the other end rather than using the built in one? Does anyone have any example code?
- iOS WatchKit - how to determine if your code is running in watch extension or the app
- Display one thing on iPad and another on Apple Tv?
- iPhone simulator plays video, real device won't
- Type 'String.Index' does not conform protocol 'IntegerLiteralConvertible'
- Create iOS BLE HID service?
- Alternative ways to push view controllers with storyboard programmatically
Solutions Collect From Internet About “IOS7 Multipeer Connectivity Creating custom nearby browser list using advertiser's discovery Info”
I suggest creating your own tableView to display the list of nearby devices from your MCBrowser.
I am creating a wrapper with convenient methods so that you can populate the nearby devices much more easily. https://github.com/thkien/THMultipeer
First set your discovery info as you want before you start broadcasting (this is including advertising
THMultipeer.me().serviceType = "thkeen-test" THMultipeer.me().info = ["model": UIDevice.currentDevice().model] THMultipeer.me().broadcast()
Now you have full control of how you want to populate the UI. All you need to do is implement the delegate in your view controller:
- (void)multipeerNewPeerFound:(MCPeerID*)peerID withName:(NSString*)name andInfo:(NSDictionary*)info atIndex:(NSInteger)index; - (void)multipeerPeerLost:(MCPeerID*)peerID atIndex:(NSInteger)index; - (void)multipeerAllPeersRemoved;
If you want to get the whole list of peers, simply call:
THMultipeer.me().peers (Swift language)
Everything is already handled by the library. Yet the part I have not done is the custom MCSession, I’m only done with the Discovery part. Hope I can finish it in 2 – 4 weeks. The library is in Objective-C so it should be backward compatible.
- protocol associated type typealias assignment compile error
- How to suppress a specific warning in Swift
- Noop for Swift's Exhaustive Switch Statements
- iPhone SDK, how to get NSDate object of coming friday's 20:00?
- Swift – Property with type and protocol
- How to show keyboard without touching the UISearchbar?
- How can I export DAE files for use in Scene Kit without seeing “untitled-animations”?
- What are the Dangers of Method Swizzling in Objective C?
- Why we can't change FetchRequest at NSFetchedResultsController?
- 'Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
- iOS: different addSubview behavior between iOS 4.3 and 5.0
- Facebook sdk is not a dylib error after update update Xcode 7?
- How to Build FFMpeg as iOS Framework
- UIDocumentPickerViewController – How to set the navigation bar color
- AlamofireImage how to clean memory and cache