Class

MCNearbyServiceAdvertiser

The MCNearbyServiceAdvertiser class publishes an advertisement for a specific service that your app provides through the Multipeer Connectivity framework and notifies its delegate about invitations from nearby peers.

Declaration

class MCNearbyServiceAdvertiser : NSObject

Overview

Before you can advertise a service, you must create an MCPeerID object that identifies your app and the user to nearby devices.

The serviceType parameter is a short text string used to describe the app's networking protocol. It should be in the same format as a Bonjour service type: 1–15 characters long and valid characters include ASCII lowercase letters, numbers, and the hyphen, containing at least one letter and no adjacent hyphens. A short name that distinguishes itself from unrelated services is recommended; for example, a text chat app made by ABC company could use the service type "abc-txtchat". For more information about service types, read Domain Naming Conventions.

The discoveryInfo parameter is a dictionary of string key/value pairs that will be advertised for browsers to see. The content of discoveryInfo will be advertised within Bonjour TXT records, so you should keep the dictionary small for better discovery performance.

For more information about TXT records, read Bonjour Operations.

Topics

Configuring and Initialization

var delegate: MCNearbyServiceAdvertiserDelegate?

The delegate object that handles advertising-related events.

var discoveryInfo: [String : String]?

The info dictionary passed when this object was initialized.

var myPeerID: MCPeerID

The local peer ID for this instance.

var serviceType: String

The service type that your app is advertising

Starting and Stopping Advertisement

func startAdvertisingPeer()

Begins advertising the service provided by a local peer.

func stopAdvertisingPeer()

Stops advertising the service provided by a local peer.

Relationships

Inherits From

Conforms To