Initializes the receiver for publishing a network service of type
type at the socket location specified by
- iOS 2.0+
- macOS 10.2+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
The domain for the service. To use the default registration domains, pass in an empty string (
@""). To limit registration to the local domain, use
You can also use a
NSNetobject to obtain a list of possible domains in which you can publish your service.
The network service type.
typemust contain both the service type and transport layer information. To ensure that the mDNS responder searches for services, as opposed to hosts, prefix both the service name and transport layer name with an underscore character (“_”). For example, to search for an HTTP service on TCP, you would use the type string "
_http". Note that the period character at the end of the string, which indicates that the domain name is an absolute name, is required.
The name by which the service is identified to the network. The name must be unique. If you pass the empty string (
@""), the system automatically advertises your service using the computer name as the service name.
The port on which the service is published.
If you specify the
NSNetflag, you may pass zero (
Service Listen For Connections
0), in which case the service automatically allocates an arbitrary (ephemeral) port for your service. When the delegate’s
netis called, you can determine the actual port chosen by calling the service object’s
Service Did Publish(_:)
Netmethod or accessing the corresponding property.
If your app is listening for connections on its own, the value of
portmust be a port number acquired by your application for the service.
You use this method to create a service that you wish to publish on the network. Although you can also use this method to create a service you wish to resolve on the network, it is generally more appropriate to use the
init(domain: method instead.
When publishing a service, you must provide valid arguments in order to advertise your service correctly. If the host computer has access to multiple registration domains, you must create separate
NSNet objects for each domain. If you attempt to publish in a domain for which you do not have registration authority, your request may be denied.
It is acceptable to use an empty string for the
domain argument when publishing or browsing a service, but do not rely on this for resolution.
This method is the designated initializer.