MultiPeer

class MultiPeer: NSObject

Undocumented

  • Undocumented

    Declaration

    Swift

    static let instance = MultiPeer()
  • Conforms to MultiPeerDelegate: Handles receiving data and changes in connections

    Declaration

    Swift

    weak var delegate: MultiPeerDelegate?
  • Name of MultiPeer session: Up to one hyphen (-) and 15 characters

    Declaration

    Swift

    var serviceType: String!
  • Device’s name

    Declaration

    Swift

    var devicePeerID: MCPeerID!
  • Advertises session

    Declaration

    Swift

    var serviceAdvertiser: MCNearbyServiceAdvertiser!
  • Browses for sessions

    Declaration

    Swift

    var serviceBrowser: MCNearbyServiceBrowser!
  • Amount of time to spend connecting before timeout

    Declaration

    Swift

    var connectionTimeout = 10.0
  • Peers available to connect to

    Declaration

    Swift

    var availablePeers: [Peer] = []
  • Peers connected to

    Declaration

    Swift

    var connectedPeers: [Peer] = []
  • Names of all connected devices

    Declaration

    Swift

    var connectedDeviceNames: [String]
  • Prints out all errors and status updates

    Declaration

    Swift

    var debugMode = false
  • Main session object that manages the current connections

    Declaration

    Swift

    lazy var session: MCSession =
  • Initializes the MultiPeer service with a serviceType and the default deviceName

    Declaration

    Swift

    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

    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

  • Undocumented

    Declaration

    Swift

    deinit
  • HOST: Automatically browses and invites all found devices

    Declaration

    Swift

    func startInviting()
  • JOIN: Automatically advertises and accepts all invites

    Declaration

    Swift

    func startAccepting()
  • HOST and JOIN: Uses both advertising and browsing to connect.

    Declaration

    Swift

    func autoConnect()
  • Stops the invitation process

    Declaration

    Swift

    func stopInviting()
  • Stops accepting invites and becomes invisible on the network

    Declaration

    Swift

    func stopAccepting()
  • Stops all invite/accept services

    Declaration

    Swift

    func stopSearching()
  • Disconnects from the current session and stops all searching activity

    Declaration

    Swift

    func disconnect()
  • Stops all invite/accept services, disconnects from the current session, and stops all searching activity

    Declaration

    Swift

    func end()
  • Undocumented

    Declaration

    Swift

    var isConnected: Bool
  • Sends an object (and type) to all connected peers.

    Declaration

    Swift

    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

    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.