Instance Method

initWithDomain:type:name:

Returns the receiver, initialized as a network service of a given type and sets the initial host information.

Declaration

- (instancetype)initWithDomain:(NSString *)domain type:(NSString *)type name:(NSString *)name;

Parameters

domain

The domain for the service. To resolve in the default domains, pass in an empty string (@""). To limit resolution to the local domain, use @"local.".

If you are creating this object to resolve a service whose information your app stored previously, you should set this to the domain in which the service was originally discovered.

You can also use a NSNetServiceBrowser object to obtain a list of possible domains in which you can discover and resolve services.

type

The network service type.

type must 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._tcp.". Note that the period character at the end of the string, which indicates that the domain name is an absolute name, is required.

name

The name of the service to resolve.

Return Value

The receiver, initialized as a network service named name of type type in the domain domain.

Discussion

This method is the appropriate initializer to use to resolve a service—to publish a service, use initWithDomain:type:name:port:.

If you know the values for domain, type, and name of the service you wish to connect to, you can create an NSNetService object using this initializer and call resolveWithTimeout: on the result.

You cannot use this initializer to publish a service. This initializer passes an invalid port number to the designated initializer, which prevents the service from being registered. Calling publish on an NSNetService object initialized with this method generates a call to your delegate’s netService:didNotPublish: method with an NSNetServicesBadArgumentError error.

See Also

Creating Network Services

- initWithDomain:type:name:port:

Initializes the receiver for publishing a network service of type type at the socket location specified by domain, name, and port.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software