Mac Developer Library

Developer

Foundation Framework Reference NSNetServiceBrowser Class Reference

Options
Deployment Target:

On This Page
Language:

NSNetServiceBrowser

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.2 and later.

The NSNetServiceBrowser class defines an interface for finding published services on a network using multicast DNS. An instance of NSNetServiceBrowser is known as a network service browser.

Services can range from standard services, such as HTTP and FTP, to custom services defined by other applications. You can use a network service browser in your code to obtain the list of accessible domains and then to obtain an NSNetService object for each discovered service. Each network service browser performs one search at a time, so if you want to perform multiple simultaneous searches, use multiple network service browsers.

A network service browser performs all searches asynchronously using the current run loop to execute the search in the background. Results from a search are returned through the associated delegate object, which your client application must provide. Searching proceeds in the background until the object receives a stop message.

To use an NSNetServiceBrowser object to search for services, allocate it, initialize it, and assign a delegate. (If you wish, you can also use the scheduleInRunLoop:forMode: and removeFromRunLoop:forMode: methods to execute searches on a run loop other than the current one.) Once your object is ready, you begin by gathering the list of accessible domains using either the searchForRegistrationDomains or searchForBrowsableDomains methods. From the list of returned domains, you can pick one and use the searchForServicesOfType:inDomain: method to search for services in that domain.

The NSNetServiceBrowser class provides two ways to search for domains. In most cases, your client should use the searchForRegistrationDomains method to search only for local domains to which the host machine has registration authority. This is the preferred method for accessing domains as it guarantees that the host machine can connect to services in the returned domains. Access to domains outside this list may be more limited.

  • Initializes an allocated NSNetServiceBrowser object.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    Initialized NSNetServiceBrowser object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • delegate delegate Property

    The delegate object for this instance.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSNetServiceBrowserDelegate?

    Objective-C

    @property(assign) id< NSNetServiceBrowserDelegate > delegate

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Adds the receiver to the specified run loop.

    Declaration

    Swift

    func scheduleInRunLoop(_ runLoop: NSRunLoop, forMode runLoopMode: String)

    Objective-C

    - (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)runLoopMode

    Parameters

    runLoop

    Run loop in which to schedule the receiver.

    runLoopMode

    Run loop mode in which to perform this operation, such as NSDefaultRunLoopMode. See the Run Loop Modes section of the NSRunLoop class for other run loop mode values.

    Discussion

    You can use this method in conjunction with removeFromRunLoop:forMode: to transfer the receiver to a run loop other than the default one. You should not attempt to run the receiver on multiple run loops.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Removes the receiver from the specified run loop.

    Declaration

    Swift

    func removeFromRunLoop(_ runLoop: NSRunLoop, forMode runLoopMode: String)

    Objective-C

    - (void)removeFromRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)runLoopMode

    Parameters

    runLoop

    Run loop from which to remove the receiver.

    runLoopMode

    Run loop mode in which to perform this operation, such as NSDefaultRunLoopMode. See the Run Loop Modes section of the NSRunLoop class for other run loop mode values.

    Discussion

    You can use this method in conjunction with scheduleInRunLoop:forMode: to transfer the receiver to a run loop other than the default one. Although it is possible to remove an NSNetService object completely from any run loop and then attempt actions on it, you must not do it.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 and later.