NSNetServiceDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 4.0 and later.
Declared in
NSNetServices.h
Companion guides
Related sample code

Overview

The NSNetServiceDelegate protocol defines the optional methods implemented by delegates of NSNetService objects.

Tasks

Using Network Services

Accepting Connections

Instance Methods

netService:didAcceptConnectionWithInputStream:outputStream:

Called when a client connects to a service managed by Bonjour.

- (void)netService:(NSNetService *)sender didAcceptConnectionWithInputStream:(NSInputStream *)inputStream outputStream:(NSOutputStream *)outputStream
Parameters
sender

The net service object that the client connected to.

inputStream

A stream object for receiving data from the client.

outputStream

A stream object for sending data to the client.

Discussion

When you publish a service, if you set the NSNetServiceListenForConnections flag in the service options, the service object accepts connections on behalf of your app. Later, when a client connects to that service, the service object calls this method to provide the app with a pair of streams for communicating with that client.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSNetServices.h

netService:didNotPublish:

Notifies the delegate that a service could not be published.

- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
Parameters
sender

The service that could not be published.

errorDict

A dictionary containing information about the problem. The dictionary contains the keys NSNetServicesErrorCode and NSNetServicesErrorDomain.

Discussion

This method may be called long after a netServiceWillPublish: message has been delivered to the delegate.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h

netService:didNotResolve:

Informs the delegate that an error occurred during resolution of a given service.

- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict
Parameters
sender

The service that did not resolve.

errorDict

A dictionary containing information about the problem. The dictionary contains the keys NSNetServicesErrorCode and NSNetServicesErrorDomain.

Discussion

Clients may try to resolve again upon receiving this error. For example, a DNS rotary may yield different IP addresses on different resolution requests.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h

netService:didUpdateTXTRecordData:

Notifies the delegate that the TXT record for a given service has been updated.

- (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData *)data
Parameters
sender

The service whose TXT record was updated.

data

The new TXT record.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
See Also
Declared In
NSNetServices.h

netServiceDidPublish:

Notifies the delegate that a service was successfully published.

- (void)netServiceDidPublish:(NSNetService *)sender
Parameters
sender

The service that was published.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h

netServiceDidResolveAddress:

Informs the delegate that the address for a given service was resolved.

- (void)netServiceDidResolveAddress:(NSNetService *)sender
Parameters
sender

The service that was resolved.

Discussion

The delegate can use the addresses method to retrieve the service’s address.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
See Also
Declared In
NSNetServices.h

netServiceDidStop:

Informs the delegate that a publish or resolveWithTimeout: request was stopped.

- (void)netServiceDidStop:(NSNetService *)sender
Parameters
sender

The service that stopped.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h

netServiceWillPublish:

Notifies the delegate that the network is ready to publish the service.

- (void)netServiceWillPublish:(NSNetService *)sender
Parameters
sender

The service that is ready to publish.

Discussion

Publication of the service proceeds asynchronously and may still generate a call to the delegate’s netService:didNotPublish: method if an error occurs.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h

netServiceWillResolve:

Notifies the delegate that the network is ready to resolve the service.

- (void)netServiceWillResolve:(NSNetService *)sender
Parameters
sender

The service that the network is ready to resolve.

Discussion

Resolution of the service proceeds asynchronously and may still generate a call to the delegate’s netService:didNotResolve: method if an error occurs.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSNetServices.h