MCNearby 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.
- iOS 7.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
Before you can advertise a service, you must create an
MCPeer object that identifies your app and the user to nearby devices.
service 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.
discovery parameter is a dictionary of string key/value pairs that will be advertised for browsers to see. The content of
discovery 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.