Mac Developer Library

Developer

Foundation Framework Reference NSNetServiceDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSNetServiceDelegate

Inheritance


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.6 and later.

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

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

    Declaration

    Swift

    optional func netServiceWillPublish(_ sender: NSNetService)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Notifies the delegate that a service could not be published.

    Declaration

    Swift

    optional func netService(_ sender: NSNetService, didNotPublish errorDict: [NSObject : AnyObject])

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

  • Notifies the delegate that a service was successfully published.

    Declaration

    Swift

    optional func netServiceDidPublish(_ sender: NSNetService)

    Objective-C

    - (void)netServiceDidPublish:(NSNetService *)sender

    Parameters

    sender

    The service that was published.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func netServiceWillResolve(_ sender: NSNetService)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func netService(_ sender: NSNetService, didNotResolve errorDict: [NSObject : AnyObject])

    Objective-C

    - (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. A common error condition is that no addresses were resolved during the timeout period specified in resolveWithTimeout:.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func netServiceDidResolveAddress(_ sender: NSNetService)

    Objective-C

    - (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. If the delegate needs only one address, it can stop the resolution process using stop. Otherwise, the resolution will continue until the timeout specified in resolveWithTimeout: is reached.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    addresses (NSNetService)

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

    Declaration

    Swift

    optional func netService(_ sender: NSNetService, didUpdateTXTRecordData data: NSData)

    Objective-C

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

    Parameters

    sender

    The service whose TXT record was updated.

    data

    The new TXT record.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

    Available as part of an informal protocol prior to OS X v10.6.

    See Also

    startMonitoring (NSNetService)

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

    Declaration

    Swift

    optional func netServiceDidStop(_ sender: NSNetService)

    Objective-C

    - (void)netServiceDidStop:(NSNetService *)sender

    Parameters

    sender

    The service that stopped.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func netService(_ sender: NSNetService, didAcceptConnectionWithInputStream inputStream: NSInputStream, outputStream outputStream: NSOutputStream)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.