IOS7 Multipeer Connectivity使用广告商的发现信息创建附近的自定义浏览器列表 [英] IOS7 Multipeer Connectivity Creating custom nearby browser list using advertiser's discovery Info
问题描述
我在IOS7中使用多重连接框架来制作聊天应用程序。我正在使用内置的 MCBrowserViewController 来显示附近的同行列表。
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.
我认为可以通过在初始化广告商时通过discoveryInfo传递数据来实现。我像这样传递discoveryInfo数据:
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];
但有没有办法创建一个自定义MCBrowserViewController,在另一端显示discoveryInfo而不是使用内置的一个?有没有人有任何示例代码?
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?
推荐答案
我建议您创建自己的tableView以显示MCBrowser中附近设备的列表。
I suggest creating your own tableView to display the list of nearby devices from your MCBrowser.
我正在使用方便的方法创建一个包装器,以便您可以更轻松地填充附近的设备。 https://github.com/thkien/THMultipeer
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 and browsing):
THMultipeer.me().serviceType = "thkeen-test"
THMultipeer.me().info = ["model": UIDevice.currentDevice().model]
THMultipeer.me().broadcast()
现在,您可以完全控制填充UI的方式。您需要做的就是在视图控制器中实现委托:
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;
如果您想获得整个同行列表,只需致电: THMultipeer .me()。peers
(Swift语言)
If you want to get the whole list of peers, simply call: THMultipeer.me().peers
(Swift language)
库已经处理了所有内容。然而我尚未完成的部分是自定义MCSession,我只完成了 Discovery 部分。希望我能在2到4周内完成它。该库位于Objective-C中,因此它应该向后兼容。
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.
这篇关于IOS7 Multipeer Connectivity使用广告商的发现信息创建附近的自定义浏览器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!