[英]Creating a custom MCBrowserViewController
Is there a way to create a UITableView
housing the same information found in an MCBrowserViewController
? 有没有办法创建一个
UITableView
容纳MCBrowserViewController
的相同信息? My current code only allows a standard view to be pushed that is not in the same design as my app: 我当前的代码只允许推送与我的app不在同一设计中的标准视图:
self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:@"chat" session:self.mySession];
[self presentViewController:self.browserVC animated:YES completion:nil];
Any ideas? 有任何想法吗? Thanks in advance!
提前致谢!
MCNearbyServiceBrowser
and MCSession
(ie <MCNearbyServiceBrowserDelegate, MCSessionDelegate>
) MCNearbyServiceBrowser
和MCSession
的委托(即<MCNearbyServiceBrowserDelegate, MCSessionDelegate>
) MCNearbyServiceBrowser
(and MCSession
) MCNearbyServiceBrowser
(和MCSession
)创建一个属性 In viewDidLoad
(or whichever trigger suits your pattern) of your View Controller: 在视图控制器的
viewDidLoad
(或适合您的模式的触发器)中:
_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];
Implement the - (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info
method as so: 实现
- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info
方法如下:
UITableView
. UITableView
的数据源的数组中。 Typically you'd get the peerID.displayName
. peerID.displayName
。 [tableView reloadData]
. [tableView reloadData]
。 Check out MCSessionP2P , a demo app that illustrates the ad-hoc networking features of MCSession
. 退房MCSessionP2P ,演示应用程序,说明了临时网络功能
MCSession
。 SessionController
conforms to MCSessionDelegate
, MCNearbyServiceBrowserDelegate
and MCNearbyServiceAdvertiserDelegate
and acts as the datasource for a UITableView
. SessionController
符合MCSessionDelegate
, MCNearbyServiceBrowserDelegate
和MCNearbyServiceAdvertiserDelegate
并充当UITableView
的数据源。 The app advertises itself via Wi-Fi or Bluetooth and programmatically connects to available peers, establishing a peer-to-peer network. 该应用程序通过Wi-Fi或蓝牙进行广告宣传,并以编程方式连接到可用的对等点,建立点对点网络。
Yazid's answer was working for me. 亚齐德的回答对我有用。 Next step, to connect to a peer that was found during
startBrowsingForPeers
use 下一步,连接到在
startBrowsingForPeers
使用期间找到的对等方
_browser.invitePeer(peerID, toSession: _mySession, withContext: nil, timeout: 30.0)
(SWIFT notation here) (SWIFT表示法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.