MultiPeer
public class MultiPeer : NSObject
extension MultiPeer: MCNearbyServiceAdvertiserDelegate
extension MultiPeer: MCNearbyServiceBrowserDelegate
extension MultiPeer: MCSessionDelegate
Main Class for MultiPeer
-
Singleton instance - call via MultiPeer.instance
Declaration
Swift
public static let instance: MultiPeer
-
Conforms to MultiPeerDelegate: Handles receiving data and changes in connections
Declaration
Swift
public weak var delegate: MultiPeerDelegate?
-
Amount of time to spend connecting before timeout
Declaration
Swift
public var connectionTimeout: Double
-
Peers available to connect to
Declaration
Swift
public var availablePeers: [Peer]
-
Peers connected to
Declaration
Swift
public var connectedPeers: [Peer]
-
Names of all connected devices
Declaration
Swift
public var connectedDeviceNames: [String] { get }
-
Prints out all errors and status updates
Declaration
Swift
public var debugMode: Bool
-
Initializes the MultiPeer service with a serviceType and the default deviceName
Declaration
Swift
public func initialize(serviceType: String)
Parameters
serviceType
String with name of MultiPeer service. Up to one hyphen (-) and 15 characters. Uses default device name
-
Initializes the MultiPeer service with a serviceType and a custom deviceName
Declaration
Swift
public func initialize(serviceType: String, deviceName: String)
Parameters
serviceType
String with name of MultiPeer service. Up to one hyphen (-) and 15 characters.
deviceName
String containing custom name for device
-
HOST: Automatically browses and invites all found devices
Declaration
Swift
public func startInviting()
-
JOIN: Automatically advertises and accepts all invites
Declaration
Swift
public func startAccepting()
-
HOST and JOIN: Uses both advertising and browsing to connect.
Declaration
Swift
public func autoConnect()
-
Stops the invitation process
Declaration
Swift
public func stopInviting()
-
Stops accepting invites and becomes invisible on the network
Declaration
Swift
public func stopAccepting()
-
Stops all invite/accept services
Declaration
Swift
public func stopSearching()
-
Disconnects from the current session and stops all searching activity
Declaration
Swift
public func disconnect()
-
Stops all invite/accept services, disconnects from the current session, and stops all searching activity
Declaration
Swift
public func end()
-
Returns true if there are any connected peers
Declaration
Swift
public var isConnected: Bool { get }
-
Sends an object (and type) to all connected peers.
Declaration
Swift
public func send(object: Any, type: UInt32)
Parameters
object
Object (Any) to send to all connected peers.
type
Type of data (UInt32) sent After sending the object, you can use the extension for Data,
convertData()
to convert it back into an object. -
Sends Data (and type) to all connected peers.
Declaration
Swift
public func send(data: Data, type: UInt32)
Parameters
data
Data (Data) to send to all connected peers.
type
Type of data (UInt32) sent After sending the data, you can use the extension for Data,
convertData()
to convert it back into data.
-
Received invitation
Declaration
Swift
public func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void)
-
Error, could not start advertising
Declaration
Swift
public func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error)
-
Found a peer, update the list of available peers
Declaration
Swift
public func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?)
-
Lost a peer, update the list of available peers
Declaration
Swift
public func browser(_ browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID)
-
Error, could not start browsing
Declaration
Swift
public func browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error)
-
Peer changed state, update all connected peers and send new connection list to delegate connectedDevicesChanged
Declaration
Swift
public func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState)
-
Received data, update delegate didRecieveData
Declaration
Swift
public func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID)
-
Received stream
Declaration
Swift
public func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID)
-
Started receiving resource
Declaration
Swift
public func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress)
-
Finished receiving resource
Declaration
Swift
public func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?)