MCNearbyServiceBrowser

1 MCNearbyServiceBrowser

  1. Initializing the Browser
  2. Browsing for Peers
  3. Inviting Peers

2 MCSessionDelegate

  1. Error Handling Delegate Methods
  2. Peer Discovery Delegate Methods

1 MCNearbyServiceBrowser

MCNearbyServiceBrowser主要用于发现附近的设备。

1.1 Initializing the Browser

/// 初始化MCNearbyServiceBrowser
public init(peer myPeerID: MCPeerID, serviceType: String)

/// MCNearbyServiceBrowserDelegate代理
weak public var delegate: MCNearbyServiceBrowserDelegate?
/// 当前MCPeerID
public var myPeerID: MCPeerID { get }
/// service类型
public var serviceType: String { get }

1.2 Browsing for Peers

/// 开始搜索设备
public func startBrowsingForPeers()
/// 结束搜索设备
public func stopBrowsingForPeers()

1.3 Inviting Peers

/// 邀请设备加入会话
public func invitePeer(peerID: MCPeerID, toSession session: MCSession, withContext context: NSData?, timeout: NSTimeInterval)

2 MCSessionDelegate

2.1 Error Handling Delegate Methods

// 开启搜索附近设备失败
@available(iOS 7.0, *)
optional public func browser(browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: NSError)

2.2 Peer Discovery Delegate Methods

// 发现附近的MCPeerID
@available(iOS 7.0, *)
public func browser(browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?)

// 某个MCPeerID消失了
@available(iOS 7.0, *)
public func browser(browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID)

 

Appendix

Sample Code

Swift

Multipeer Connectivity Framework Reference

MCNearbyServiceBrowser Class Reference

MCNearbyServiceBrowserDelegate Protocol Reference

Revision History

时间 描述
2016-01-22 博文完成

CSDN:http://blog.csdn.net/y550918116j

GitHub:https://github.com/937447974/Blog

你可能感兴趣的:(MCNearbyServiceBrowser)