iOS Developer Library — Pre-Release

Developer

Foundation Framework Reference NSNetServiceBrowser Class Reference

Options
Deployment Target:

On This Page
Language:

NSNetServiceBrowser

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

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 2.0 and later.
  • Initializes an allocated NSNetServiceBrowser object.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    Initialized NSNetServiceBrowser object.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Initiates a search for domains visible to the host. This method returns immediately.

    Declaration

    Swift

    func searchForBrowsableDomains()

    Objective-C

    - (void)searchForBrowsableDomains

    Discussion

    The delegate receives a netServiceBrowser:didFindDomain:moreComing: message for each domain discovered.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Initiates a search for domains in which the host may register services.

    Declaration

    Swift

    func searchForRegistrationDomains()

    Objective-C

    - (void)searchForRegistrationDomains

    Discussion

    This method returns immediately, sending a netServiceBrowserWillSearch: message to the delegate if the network was ready to initiate the search. The delegate receives a subsequent netServiceBrowser:didFindDomain:moreComing: message for each domain discovered.

    Most network service browser clients do not have to use this method—it is sufficient to publish a service with the empty string, which registers it in any available registration domains automatically.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Starts a search for services of a particular type within a specific domain.

    Declaration

    Swift

    func searchForServicesOfType(_ serviceType: String, inDomain domainName: String)

    Objective-C

    - (void)searchForServicesOfType:(NSString *)serviceType inDomain:(NSString *)domainName

    Parameters

    serviceType

    Type of the service to search for.

    domainName

    Domain name in which to perform the search.

    Discussion

    This method returns immediately, sending a netServiceBrowserWillSearch: message to the delegate if the network was ready to initiate the search.The delegate receives subsequent netServiceBrowser:didFindService:moreComing: messages for each service discovered.

    The serviceType argument must contain both the service type and transport layer information. To ensure that the mDNS responder searches for services, rather than hosts, make sure to 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 is required.

    The domainName argument can be an explicit domain name, the generic local domain @"local." (note trailing period, which indicates an absolute name), or the empty string (@""), which indicates the default registration domains. Usually, you pass in an empty string. Note that it is acceptable to use an empty string for the domainName argument when publishing or browsing a service, but do not rely on this for resolution.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    netServiceBrowser:didFindService:moreComing: (NSNetServiceBrowserDelegate)
    netServiceBrowserWillSearch: (NSNetServiceBrowserDelegate)

  • Halts a currently running search or resolution.

    Declaration

    Swift

    func stop()

    Objective-C

    - (void)stop

    Discussion

    This method sends a netServiceBrowserDidStopSearch: message to the delegate and causes the browser to discard any pending search results.

    Import Statement

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    netServiceBrowserDidStopSearch: (NSNetServiceBrowserDelegate)