Iphone 创建自定义MCBrowserViewController

Iphone 创建自定义MCBrowserViewController,iphone,objective-c,uitableview,ios7,multipeer-connectivity,Iphone,Objective C,Uitableview,Ios7,Multipeer Connectivity,有没有办法创建一个包含MCBrowserViewController中相同信息的UITableView?我的当前代码只允许推送与我的应用程序设计不同的标准视图: self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:@"chat" session:self.mySession]; [self presentViewController:self.browserVC animated:YES completion

有没有办法创建一个包含
MCBrowserViewController
中相同信息的
UITableView
?我的当前代码只允许推送与我的应用程序设计不同的标准视图:

self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:@"chat" session:self.mySession];
[self presentViewController:self.browserVC animated:YES completion:nil];
有什么想法吗?提前谢谢

  • 将视图控制器作为代理设置为
    MCNearbyServiceBrowser
    MCSession
    (即
  • 为您的
    MCNearbyServiceBrowser
    (和
    MCSession
    )创建属性
  • 在视图控制器的
    viewdiload
    (或适合您模式的触发器)中:

    _myPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].name];
    _mySession = [[MCSession alloc] initWithPeer:_myPeerID];
    [_mySession setDelegate:self];
    _browser = [[MCNearbyServiceBrowser alloc]initWithPeer:_myPeerID serviceType:@"connectme"];
    [_browser setDelegate:self];
    [_browser startBrowsingForPeers];
    
  • 实现
    -(void)browser:(MCNearbyServiceBrowser*)browser foundPeer:(mcperied*)peerID with discoveryinfo:(NSDictionary*)info
    方法,如下所示:

  • 将找到的每个对等点添加到
    UITableView
    数据源的数组中。通常您会得到
    peerID.displayName
  • 调用
    [tableView reloadData]

  • Check out,一个演示应用程序,演示了
    MCSession
    的特别网络功能
    SessionController
    符合
    MCSessionDelegate
    MCNearbyServiceBrowserDelegate
    MCNearbyServiceAdvertiserDelegate
    ,并充当
    UITableView
    的数据源。该应用程序通过Wi-Fi或蓝牙进行自我宣传,并通过编程方式连接到可用的对等方,建立对等网络。

    Yazid的答案对我有用。下一步,连接到在
    startBrowsingForPeers
    use期间找到的对等方

    _browser.invitePeer(peerID, toSession: _mySession, withContext: nil, timeout: 30.0)
    
    (此处为SWIFT符号)

    WWDC 2013年题为“具有多个EER连接的附近网络”的会议在演讲的“高级”部分讨论了这一点。它还描述了在各种委托方法中需要执行的操作。