iOS Developer Library

Developer

CoreServices Framework Reference CFNetServices Reference

Options
Deployment Target:

On This Page
Language:

CFNetServices Reference

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import CFNetwork

Objective-C

@import CFNetwork;

The CFNetServices API is part of Bonjour, Apple’s implementation of zero-configuration networking (ZEROCONF). The CFNetServices API allows you to register a network service, such as a printer or file server, so that it can be found by name or browsed for by service type and domain. Applications can use the CFNetServices API to discover the services that are available on the network and to find all access information — such as name, IP address, and port number — needed to use each service.

In effect, Bonjour registration and discovery combine the functions of a local DNS server and AppleTalk, allowing applications to provide the kind of user-friendly browsing available in the AppleTalk Chooser using open protocols, such as Multicast DNS (mDNS). Bonjour gives applications easy access to services over local IP networks without requiring the service to support an AppleTalk stack, and without requiring a DNS server on the local network.

For a full description of Bonjour, see Bonjour Overview.

Functions

  • Creates an instance of a Network Service object.

    Declaration

    Swift

    func CFNetServiceCreate(_ alloc: CFAllocator!, _ domain: CFString!, _ type: CFString!, _ name: CFString!, _ port: Int32) -> Unmanaged<CFNetService>!

    Objective-C

    CFNetServiceRef CFNetServiceCreate ( CFAllocatorRef alloc, CFStringRef domain, CFStringRef serviceType, CFStringRef name, SInt32 port );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    domain

    The domain in which the CFNetService is to be registered; cannot be NULL. Call CFNetServiceBrowserCreate and CFNetServiceBrowserSearchForDomains to get the registration domain.

    type

    The type of service being registered; cannot be NULL. For a list of valid service types, see http://www.iana.org/assignments/port-numbers.

    name

    A unique name if the instance will be used to register a service. The name will become part of the instance name in the DNS records that will be created when the service is registered. If the instance will be used to resolve a service, the name should be the name of the machine or service that will be resolved.

    port

    Local IP port, in host byte order, on which this service accepts connections. Pass zero to get placeholder service. With a placeholder service, the service will not be discovered by browsing, but a name conflict will occur if another client tries to register the same name. Most applications do not need to use placeholder service.

    Return Value

    A new net service object, or NULL if the instance could not be created. Ownership follows the The Create Rule.

    Discussion

    If the service depends on information in DNS TXT records, call CFNetServiceSetProtocolSpecificInformation.

    If the CFNetService is to run in asynchronous mode, call CFNetServiceSetClient to prepare the service for running in asynchronous mode. Then call CFNetServiceScheduleWithRunLoop to schedule the service on a run loop. Then call CFNetServiceRegister to make the service available.

    If the CFNetService is to run in synchronous mode, call CFNetServiceRegister.

    To terminate a service that is running in asynchronous mode, call CFNetServiceCancel and CFNetServiceUnscheduleFromRunLoop.

    To terminate a service that is running in synchronous mode, call CFNetServiceCancel.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Creates a copy of a CFNetService object.

    Declaration

    Swift

    func CFNetServiceCreateCopy(_ alloc: CFAllocator!, _ service: CFNetService!) -> Unmanaged<CFNetService>!

    Objective-C

    CFNetServiceRef CFNetServiceCreateCopy ( CFAllocatorRef alloc, CFNetServiceRef service );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    service

    CFNetServiceRef to be copied; cannot be NULL. If service is not a valid CFNetServiceRef, the behavior of this function is undefined.

    Return Value

    Copy of service, including all previously resolved data, or NULL if service could not be copied. Ownership follows the The Create Rule.

    Discussion

    This function creates a copy of the CFNetService specified by service.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Creates an instance of a NetServiceMonitor object that watches for record changes.

    Declaration

    Swift

    func CFNetServiceMonitorCreate(_ alloc: CFAllocator!, _ theService: CFNetService!, _ clientCB: CFNetServiceMonitorClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceMonitor>!

    Objective-C

    CFNetServiceMonitorRef CFNetServiceMonitorCreate ( CFAllocatorRef alloc, CFNetServiceRef theService, CFNetServiceMonitorClientCallBack clientCB, CFNetServiceClientContext *clientContext );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    theService

    CFNetService to be monitored.

    clientCB

    Pointer to callback function that is to be called when a record associated with theService changes; cannot be NULL.

    clientContext

    Pointer to user-defined contextual information that is to be passed to the callback specified by clientCB when the callback is called; cannot be NULL. For details, see CFNetServiceClientContext.

    Return Value

    A new instance of a CFNetServiceMonitor, or NULL if the monitor could not be created. Ownership follows the The Create Rule.

    Discussion

    This function creates a CFNetServiceMonitor that watches for changes in records associated with theService.

    If the CFNetServiceMonitor is to run in asynchronous mode, call CFNetServiceMonitorScheduleWithRunLoop to schedule the monitor on a run loop. Then call CFNetServiceMonitorStart to start monitoring. When a change occurs, the callback function specified by clientCB will be called. For details, see CFNetServiceMonitorClientCallBack.

    If the CFNetServiceMonitor is to run in synchronous mode, call CFNetServiceMonitorStart.

    To stop a monitor that is running in asynchronous mode, call CFNetServiceMonitorStop and CFNetServiceMonitorUnscheduleFromRunLoop.

    To stop a monitor that is running in synchronous mode, call CFNetServiceMonitorStop.

    If you no longer need to monitor record changes, call CFNetServiceMonitorStop to stop the monitor and then call CFNetServiceMonitorInvalidateto invalidate the monitor so it cannot be used again. Then call CFRelease to release the memory associated with CFNetServiceMonitorRef.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Creates an instance of a Network Service browser object.

    Declaration

    Swift

    func CFNetServiceBrowserCreate(_ alloc: CFAllocator!, _ clientCB: CFNetServiceBrowserClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceBrowser>!

    Objective-C

    CFNetServiceBrowserRef CFNetServiceBrowserCreate ( CFAllocatorRef alloc, CFNetServiceBrowserClientCallBack clientCB, CFNetServiceClientContext *clientContext );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    clientCB

    Callback function that is to be called when domains and services are found; cannot be NULL. For details, see CFNetServiceBrowserClientCallBack.

    clientContext

    Context information to be used when clientCB is called; cannot be NULL. For details, see CFNetServiceClientContext.

    Return Value

    A new browser object, or NULL if the instance could not be created. Ownership follows the The Create Rule.

    Discussion

    This function creates an instance of a Network Service browser object, called a CFNetServiceBrowser, that can be used to search for domains and for services.

    To use the resulting CFNetServiceBrowser in asynchronous mode, call CFNetServiceBrowserScheduleWithRunLoop. Then call CFNetServiceBrowserSearchForDomains and CFNetServiceBrowserSearchForServices to use the CFNetServiceBrowser to search for services and domains, respectively. The callback function specified by clientCB is called from a run loop to pass search results to your application. The search continues until you stop the search by calling CFNetServiceBrowserStopSearch.

    If you do not call CFNetServiceBrowserScheduleWithRunLoop, searches with the resulting CFNetServiceBrowser are made in synchronous mode. Calls made to CFNetServiceBrowserSearchForDomains and CFNetServiceBrowserSearchForServices block until there are search results, in which case the callback function specified by clientCB is called, until the search is are stopped by calling CFNetServiceBrowserStopSearch from another thread, or an error occurs.

    To shut down a CFNetServiceBrowser that is running in asynchronous mode, call CFNetServiceBrowserStopSearch, followed by CFNetServiceBrowserUnscheduleFromRunLoop, and then CFNetServiceBrowserInvalidate.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Invalidates an instance of a Network Service browser object.

    Declaration

    Swift

    func CFNetServiceBrowserInvalidate(_ browser: CFNetServiceBrowser!)

    Objective-C

    void CFNetServiceBrowserInvalidate ( CFNetServiceBrowserRef browser );

    Parameters

    browser

    The CFNetServiceBrowser to invalidate, obtained by a previous call to CFNetServiceBrowserCreate.

    Discussion

    This function invalidates the specified instance of a Network Service browser object. Any searches using the specified instance that are in progress when this function is called are stopped. An invalidated browser cannot be scheduled on a run loop and its callback function is never called.

    Special Considerations

    This function is thread safe as long as another thread does not alter the same CFNetServiceBrowserRef at the same time.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Schedules a CFNetServiceBrowser on a run loop.

    Declaration

    Swift

    func CFNetServiceBrowserScheduleWithRunLoop(_ browser: CFNetServiceBrowser!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceBrowserScheduleWithRunLoop ( CFNetServiceBrowserRef browser, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    browser

    The CFNetServiceBrowser that is to be scheduled on a run loop; cannot be NULL.

    runLoop

    The run loop on which the browser is to be scheduled; cannot be NULL.

    runLoopMode

    The mode on which to schedule the browser; cannot be NULL.

    Discussion

    This function schedules the specified CFNetServiceBrowser on the run loop, thereby placing the browser in asynchronous mode. The run loop will call the browser’s callback function to deliver the results of domain and service searches. The caller is responsible for ensuring that at least one of the run loops on which the browser is scheduled is being run.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Searches for domains.

    Declaration

    Swift

    func CFNetServiceBrowserSearchForDomains(_ browser: CFNetServiceBrowser!, _ registrationDomains: Boolean, _ error: UnsafeMutablePointer<CFStreamError>) -> Boolean

    Objective-C

    Boolean CFNetServiceBrowserSearchForDomains ( CFNetServiceBrowserRef browser, Boolean registrationDomains, CFStreamError *error );

    Parameters

    browser

    The CFNetServiceBrowser, obtained by previously calling CFNetServiceBrowserCreate, that is to perform the search; cannot be NULL.

    registrationDomains

    TRUE to search for only registration domains; FALSE to search for domains that can be browsed for services. For this version of the CFNetServices API, the registration domain is the local domain maintained by the mDNS responder running on the same machine as the calling application.

    error

    A pointer to a CFStreamError structure, that, if an error occurs, will be set to the error and the error’s domain and passed to your callback function. Pass NULL if you don’t want to receive the error that may occur as a result of this particular call.

    Return Value

    TRUE if the search was started (asynchronous mode); FALSE if another search is already in progress for this CFNetServiceBrowser or if an error occurred.

    Discussion

    This function uses a CFNetServiceBrowser to search for domains. The search continues until the search is canceled by calling CFNetServiceBrowserStopSearch. If registrationDomains is TRUE, this function searches only for domains in which services can be registered. If registrationDomains is FALSE, this function searches for domains that can be browsed for services. When a domain is found, the callback function specified when the CFNetServiceBrowser was created is called and passed an instance of a CFStringRef containing the domain that was found.

    In asynchronous mode, this function returns TRUE if the search was started. Otherwise, it returns FALSE.

    In synchronous mode, this function blocks until the search is stopped by calling CFNetServiceBrowserStopSearch from another thread, in which case it returns FALSE, or until an error occurs.

    Special Considerations

    This function is thread safe.

    For any one CFNetServiceBrowser, only one domain search or one service search can be in progress at the same time.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Searches a domain for services of a specified type.

    Declaration

    Swift

    func CFNetServiceBrowserSearchForServices(_ browser: CFNetServiceBrowser!, _ domain: CFString!, _ type: CFString!, _ error: UnsafeMutablePointer<CFStreamError>) -> Boolean

    Objective-C

    Boolean CFNetServiceBrowserSearchForServices ( CFNetServiceBrowserRef browser, CFStringRef domain, CFStringRef serviceType, CFStreamError *error );

    Parameters

    browser

    The CFNetServiceBrowser, obtained by previously calling CFNetServiceBrowserCreate, that is to perform the search; cannot be NULL.

    domain

    The domain to search for the service type; cannot be NULL. To get the domains that are available for searching, call CFNetServiceBrowserSearchForDomains.

    type

    The service type to search for; cannot be NULL. For a list of valid service types, see http://www.iana.org/assignments/port-numbers.

    error

    A pointer to a CFStreamError structure, that, if an error occurs, will be set to the error and the error’s domain and passed to your callback function. Pass NULL if you don’t want to receive the error that may occur as a result of this particular call.

    Return Value

    TRUE if the search was started (asynchronous mode); FALSE if another search is already in progress for this CFNetServiceBrowser or if an error occurred.

    Discussion

    This function searches the specified domain for services that match the specified service type. The search continues until the search is canceled by calling CFNetServiceBrowserStopSearch. When a match is found, the callback function specified when the CFNetServiceBrowser was created is called and passed an instance of a CFNetService representing the service that was found.

    In asynchronous mode, this function returns TRUE if the search was started. Otherwise, it returns FALSE.

    In synchronous mode, this function blocks until the search is stopped by calling CFNetServiceBrowserStopSearch from another thread, in which case this function returns FALSE, or until an error occurs.

    Special Considerations

    This function is thread safe.

    For any one CFNetServiceBrowser, only one domain search or one service search can be in progress at the same time.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Stops a search for domains or services.

    Declaration

    Swift

    func CFNetServiceBrowserStopSearch(_ browser: CFNetServiceBrowser!, _ error: UnsafeMutablePointer<CFStreamError>)

    Objective-C

    void CFNetServiceBrowserStopSearch ( CFNetServiceBrowserRef browser, CFStreamError *error );

    Parameters

    browser

    The CFNetServiceBrowser that was used to start the search; cannot be NULL.

    error

    A pointer to a CFStreamError structure that will be passed to the callback function associated with this CFNetServiceBrowser (if the search is being conducted in asynchronous mode) or that is pointed to by the error parameter when CFNetServiceBrowserSearchForDomains or CFNetServiceBrowserSearchForServices returns (if the search is being conducted in synchronous mode). Set the domain field to kCFStreamErrorDomainCustom and the error field to an appropriate value.

    Discussion

    This functions stops a search started by a previous call to CFNetServiceBrowserSearchForDomains or CFNetServiceBrowserSearchForServices. For asynchronous and synchronous searches, calling this function causes the callback function associated with the CFNetServiceBrowser to be called once for each domain or service found. If the search is asynchronous, error is passed to the callback function. If the search is synchronous, calling this function causes CFNetServiceBrowserSearchForDomains or CFNetServiceBrowserSearchForServices to return FALSE. If the error parameter for either call pointed to a CFStreamError structure, the CFStreamError structure contains the error code and the error code’s domain as set when this function was called.

    Special Considerations

    This function is thread safe.

    If you are stopping an asynchronous search, before calling this function, call CFNetServiceBrowserUnscheduleFromRunLoop, followed by CFNetServiceBrowserInvalidate.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Unschedules a CFNetServiceBrowser from a run loop and mode.

    Declaration

    Swift

    func CFNetServiceBrowserUnscheduleFromRunLoop(_ browser: CFNetServiceBrowser!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceBrowserUnscheduleFromRunLoop ( CFNetServiceBrowserRef browser, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    browser

    The CFNetServiceBrowser that is to be unscheduled; cannot be NULL.

    runLoop

    The run loop; cannot be NULL.

    runLoopMode

    The mode from which the browser is to be unscheduled; cannot be NULL.

    Discussion

    Call this function to shut down a browser that is running asynchronously. To complete the shutdown, call CFNetServiceBrowserInvalidate followed by CFNetServiceBrowserStopSearch.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Cancels a service registration or a service resolution.

    Declaration

    Swift

    func CFNetServiceCancel(_ theService: CFNetService!)

    Objective-C

    void CFNetServiceCancel ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService, obtained by previously calling CFNetServiceCreate, for which a registration or a resolution is to be canceled.

    Discussion

    This function cancels service registrations, started by CFNetServiceRegister, thereby making the service unavailable. It also cancels service resolutions, started by CFNetServiceResolve.

    If you are shutting down an asynchronous service, you should first call CFNetServiceUnscheduleFromRunLoop and CFNetServiceSetClient with clientCB set to NULL. Then call this function.

    If you are shutting down a synchronous service, call this function from another thread.

    This function also cancels service resolutions. You would want to cancel a service resolution if your callback function has received an IP address that you’ve successfully used to connect to the service. In addition, you might want to cancel a service resolution if the resolution is taking longer than a user would want to wait or if the user canceled the operation.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Uses TXT record data to create a dictionary.

    Declaration

    Swift

    func CFNetServiceCreateDictionaryWithTXTData(_ alloc: CFAllocator!, _ txtRecord: CFData!) -> Unmanaged<CFDictionary>!

    Objective-C

    CFDictionaryRef CFNetServiceCreateDictionaryWithTXTData ( CFAllocatorRef alloc, CFDataRef txtRecord );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    txtRecord

    TXT record data as returned by CFNetServiceGetTXTData.

    Return Value

    A dictionary containing the key/value pairs parsed from txtRecord, or NULL if txtRecord cannot be parsed. Each key in the dictionary is a CFString object, and each value is a CFData object. Ownership follows the The Create Rule.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Flattens a set of key/value pairs into a CFDataRef suitable for passing to CFNetServiceSetTXTData.

    Declaration

    Swift

    func CFNetServiceCreateTXTDataWithDictionary(_ alloc: CFAllocator!, _ keyValuePairs: CFDictionary!) -> Unmanaged<CFData>!

    Objective-C

    CFDataRef CFNetServiceCreateTXTDataWithDictionary ( CFAllocatorRef alloc, CFDictionaryRef keyValuePairs );

    Parameters

    alloc

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

    keyValuePairs

    CFDictionaryRef containing the key/value pairs that are to be placed in a TXT record. Each key must be a CFStringRef and each value should be a CFDataRef or a CFStringRef. (See the discussion below for additional information about values that are CFStringRefs.) This function fails if any other data types are provided. The length of a key and its value should not exceed 255 bytes.

    Return Value

    A CFData object containing the flattened form of keyValuePairs, or NULL if the dictionary could not be flattened. Ownership follows the The Create Rule.

    Discussion

    This function flattens the key/value pairs in the dictionary specified by keyValuePairs into a CFDataRef suitable for passing to CFNetServiceSetTXTData. Note that this function is not a general purpose function for flattening CFDictionaryRefs.

    The keys in the dictionary referenced by keyValuePairs must be CFStringRefs and the values must be CFDataRefs. Any values that are CFStringRefs are converted to CFDataRefs representing the flattened UTF-8 bytes of the string. The types of the values are not encoded in the CFDataRefs, so any CFStringRefs that are converted to CFDataRefs remain CFDataRefs when the CFDataRef produced by this function is processed by CFNetServiceCreateDictionaryWithTXTData.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the IP addressing from a CFNetService.

    Declaration

    Swift

    func CFNetServiceGetAddressing(_ theService: CFNetService!) -> Unmanaged<CFArray>!

    Objective-C

    CFArrayRef CFNetServiceGetAddressing ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService whose IP addressing is to be obtained; cannot be NULL.

    Return Value

    A CFArray containing a CFDataRef for each IP address returned, or NULL. Each CFDataRef consists of a sockaddr structure containing the IP address of the service. This function returns NULL if the service’s addressing is unknown because CFNetServiceResolve has not been called for theService.

    Discussion

    This function gets the IP addressing from a CFNetService. Typically, the CFNetService was obtained by calling CFNetServiceBrowserSearchForServices. Before calling this function, call CFNetServiceResolve to update the CFNetService with its IP addressing.

    Special Considerations

    This function gets the data in a thread-safe way, but the data itself is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Queries a CFNetService for its target hosts.

    Declaration

    Swift

    func CFNetServiceGetTargetHost(_ theService: CFNetService!) -> Unmanaged<CFString>!

    Objective-C

    CFStringRef CFNetServiceGetTargetHost ( CFNetServiceRef theService );

    Parameters

    theService

    Network service to be queried.

    Return Value

    The target host name of the machine providing the service or NULL is of the service’s target host is not known. (The target host will not be known if it has not been resolved.)

    Special Considerations

    This function is thread safe, but the target host name is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the domain from a CFNetService.

    Declaration

    Swift

    func CFNetServiceGetDomain(_ theService: CFNetService!) -> Unmanaged<CFString>!

    Objective-C

    CFStringRef CFNetServiceGetDomain ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService whose domain is to be obtained; cannot be NULL.

    Return Value

    A CFString object containing the domain of the CFNetService.

    Discussion

    This function gets the domain from a CFNetService.

    Special Considerations

    This function is thread safe. The function gets the data in a thread-safe way, but the data is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the name from a CFNetService.

    Declaration

    Swift

    func CFNetServiceGetName(_ theService: CFNetService!) -> Unmanaged<CFString>!

    Objective-C

    CFStringRef CFNetServiceGetName ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService whose name is to be obtained; cannot be NULL.

    Return Value

    A CFString object containing the name of the service represented by the CFNetService.

    Discussion

    This function gets the name from a CFNetService.

    Special Considerations

    This function is thread safe. The function gets the data in a thread-safe way, but the data is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • This function gets the port number from a CFNetService.

    Declaration

    Swift

    func CFNetServiceGetPortNumber(_ theService: CFNetService!) -> Int32

    Objective-C

    SInt32 CFNetServiceGetPortNumber ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService whose protocol-specific information is to be obtained; cannot be NULL. Note that in order to get protocol-specific information, you must resolve theService by calling CFNetServiceResolve or CFNetServiceResolveWithTimeout before calling this function.

    Return Value

    The port number of the service.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Queries a network service for the contents of its TXT records.

    Declaration

    Swift

    func CFNetServiceGetTXTData(_ theService: CFNetService!) -> Unmanaged<CFData>!

    Objective-C

    CFDataRef CFNetServiceGetTXTData ( CFNetServiceRef theService );

    Parameters

    theService

    Reference for the network service whose TXT record data is to be obtained; cannot be NULL. Note that in order to get TXT record data, you must resolve theService by calling CFNetServiceResolve or CFNetServiceResolveWithTimeout before calling this function.

    Return Value

    CFDataRef object containing the requested TXT data and suitable for passing to CFNetServiceCreateDictionaryWithTXTData, or NULL if the service’s TXT data has not been resolved.

    Discussion

    This function gets the data from the service’s TXT records.

    Special Considerations

    This function gets the data in a thread-safe way, but the data itself is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the type from a CFNetService.

    Declaration

    Swift

    func CFNetServiceGetType(_ theService: CFNetService!) -> Unmanaged<CFString>!

    Objective-C

    CFStringRef CFNetServiceGetType ( CFNetServiceRef theService );

    Parameters

    theService

    The CFNetService whose type is to be obtained; cannot be NULL.

    Return Value

    A CFString object containing the type from a CFNetService.

    Discussion

    This function gets the type of a CFNetService.

    Special Considerations

    This function is thread safe. The function gets the data in a thread-safe way, but the data is not safe if the service is altered from another thread.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Invalidates an instance of a Network Service monitor object.

    Declaration

    Swift

    func CFNetServiceMonitorInvalidate(_ monitor: CFNetServiceMonitor!)

    Objective-C

    void CFNetServiceMonitorInvalidate ( CFNetServiceMonitorRef monitor );

    Parameters

    monitor

    CFNetServiceMonitor to invalidate; cannot be NULL.

    Discussion

    This function invalidates the specified Network Service monitor so that it cannot be used again. Before you call this function, you should call CFNetServiceMonitorStop. If the monitor has not already been stopped, this function stops the monitor for you.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Schedules a CFNetServiceMonitor on a run loop.

    Declaration

    Swift

    func CFNetServiceMonitorScheduleWithRunLoop(_ theService: CFNetServiceMonitor!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceMonitorScheduleWithRunLoop ( CFNetServiceMonitorRef monitor, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    theService

    The CFNetServiceMonitor that is to be scheduled on a run loop; cannot be NULL.

    runLoop

    The run loop on which the monitor is to be scheduled; cannot be NULL.

    runLoopMode

    The mode on which to schedule the monitor; cannot be NULL.

    Discussion

    Schedules the specified monitor on a run loop, which places the monitor in asynchronous mode. The caller is responsible for ensuring that at least one of the run loops on which the monitor is scheduled is being run.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Starts monitoring.

    Declaration

    Swift

    func CFNetServiceMonitorStart(_ monitor: CFNetServiceMonitor!, _ recordType: CFNetServiceMonitorType, _ error: UnsafeMutablePointer<CFStreamError>) -> Boolean

    Objective-C

    Boolean CFNetServiceMonitorStart ( CFNetServiceMonitorRef monitor, CFNetServiceMonitorType recordType, CFStreamError *error );

    Parameters

    monitor

    CFNetServiceMonitor, created by calling CFNetServiceMonitorCreate, that is to be started.

    recordType

    CFNetServiceMonitorType that specified the type of record to monitor. For possible values, see CFNetServiceMonitorType Constants.

    error

    Pointer to a CFStreamError structure. If an error occurs, on output, the structure’s domain field will be set to the error code’s domain and the error field will be set to an appropriate error code. Set this parameter to NULL if you don’t want to receive the error code and its domain.

    Return Value

    TRUE if an asynchronous monitor was started successfully. FALSE if an error occurred when starting an asynchronous or synchronous monitor, or if CFNetServiceMonitorStop was called for an synchronous monitor.

    Discussion

    This function starts monitoring for changes to records of the type specified by recordType. If a monitor is already running for the service associated with the specified CFNetServiceMonitorRef, this function returns FALSE.

    For synchronous monitors, this function blocks until the monitor is stopped by calling CFNetServiceMonitorStop, in which case, this function returns FALSE.

    For asynchronous monitors, this function returns TRUE or FALSE, depending on whether monitoring starts successfully.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Stops a CFNetServiceMonitor.

    Declaration

    Swift

    func CFNetServiceMonitorStop(_ monitor: CFNetServiceMonitor!, _ error: UnsafeMutablePointer<CFStreamError>)

    Objective-C

    void CFNetServiceMonitorStop ( CFNetServiceMonitorRef monitor, CFStreamError *error );

    Parameters

    monitor

    CFNetServiceMonitor, started by calling CFNetServiceMonitorStart, that is to be stopped.

    error

    Pointer to a CFStreamError structure or NULL. For synchronous monitors, set the error field of this structure to the non-zero value you want to be set in the CFStreamError structure when CFNetServiceMonitorStart returns. Note that when it returns, CFNetServiceMonitorStart returns FALSE. If the monitor was started asynchronously, set the error field to the non-zero value you want the monitor’s callback to receive when it is called. If this parameter is NULL, default values for the CFStreamError structure are used: the domain is set to kCFStreamErrorDomainNetServices and the error code is set to kCFNetServicesErrorCancel.

    Discussion

    This function stops the specified monitor. Call CFNetServiceMonitorStart if you want to start monitoring again.

    If you want to stop monitoring and no longer need to monitor record changes, call CFNetServiceMonitorInvalidate instead of this function.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Unschedules a CFNetServiceMonitor from a run loop.

    Declaration

    Swift

    func CFNetServiceMonitorUnscheduleFromRunLoop(_ monitor: CFNetServiceMonitor!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceMonitorUnscheduleFromRunLoop ( CFNetServiceMonitorRef monitor, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    monitor

    The CFNetServiceMonitor that is to be unscheduled; cannot be NULL.

    runLoop

    The run loop; cannot be NULL.

    runLoopMode

    The mode from which the monitor is to be unscheduled; cannot be NULL.

    Discussion

    Unschedules the specified monitor from the specified run loop and mode. Call this function to shut down a monitor that is running asynchronously.

    To change a monitor so that it cannot be scheduled and so that its callback will never be called, call CFNetServiceMonitorInvalidate.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Makes a CFNetService available on the network.

    Declaration

    Swift

    func CFNetServiceRegisterWithOptions(_ theService: CFNetService!, _ options: CFOptionFlags, _ error: UnsafeMutablePointer<CFStreamError>) -> Boolean

    Objective-C

    Boolean CFNetServiceRegisterWithOptions ( CFNetServiceRef theService, CFOptionFlags options, CFStreamError *error );

    Parameters

    theService

    Network service to register; cannot be NULL. The registration will fail if the service doesn’t have a domain, a type, a name, and an IP address.

    options

    Bit flags for specifying registration options. Currently, the only registration option is kCFNetServiceFlagNoAutoRename. For details, see CFNetService Registration Options.

    error

    Pointer to a CFStreamError structure that will be set to an error code and the error code’s domain if an error occurs; or NULL if you don’t want to receive the error code and its domain.

    Return Value

    TRUE if an asynchronous service registration was started; FALSE if an asynchronous or synchronous registration failed or if a synchronous registration was canceled.

    Discussion

    If the service is to run in asynchronous mode, you must call CFNetServiceSetClient to associate a callback function with this CFNetService before calling this function.

    When registering a service that runs in asynchronous mode, this function returns TRUE if the service contains all of the required attributes and the registration process can start. If the registration process completes successfully, the service is available on the network until you shut down the service by calling CFNetServiceUnscheduleFromRunLoop, CFNetServiceSetClient, and CFNetServiceCancel. If the service does not contain all of the required attributes or if the registration process does not complete successfully, this function returns FALSE.

    When registering a service that runs in synchronous mode, this function blocks until an error occurs, in which case this function returns FALSE. Until this function returns FALSE, the service is available on the network. To force this function to return FALSE, thereby shutting down the service, call CFNetServiceCancel from another thread.

    The options parameter is a bit flag for specifying service registration options. Currently, kCFNetServiceFlagNoAutoRename is the only supported registration option. If this bit is set and a service of the same name is running, the registration will fail. If this bit is not set and a service of the same name is running, the service that is being registered will be renamed automatically by appending (n) to the service name, where n is a number that is incremented until the service can be registered with a unique name.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the IP address or addresses for a CFNetService.

    Declaration

    Swift

    func CFNetServiceResolveWithTimeout(_ theService: CFNetService!, _ timeout: CFTimeInterval, _ error: UnsafeMutablePointer<CFStreamError>) -> Boolean

    Objective-C

    Boolean CFNetServiceResolveWithTimeout ( CFNetServiceRef theService, CFTimeInterval timeout, CFStreamError *error );

    Parameters

    theService

    The CFNetService to resolve; cannot be NULL. The resolution will fail if the service doesn’t have a domain, a type, and a name.

    timeout

    Value of type CFTimeInterval specifying the maximum amount of time allowed to perform the resolution. If the resolution is not performed within the specified amount of time, a timeout error will be returned. If timeout is less than or equal to zero, an infinite amount of time is allowed.

    error

    Pointer to a CFStreamError structure that will be set to an error code and the error code’s domain if an error occurs; or NULL if you don’t want to receive the error code and its domain.

    Return Value

    TRUE if an asynchronous service resolution was started or if a synchronous service resolution updated the CFNetService; FALSE if an asynchronous or synchronous resolution failed or timed out, or if a synchronous resolution was canceled.

    Discussion

    This function updates the specified CFNetService with the IP address or addresses associated with the service. Call CFNetServiceGetAddressing to get the addresses.

    When resolving a service that runs in asynchronous mode, this function returns TRUE if the CFNetService has a domain, type, and name, and the underlying resolution process was started. Otherwise, this function returns FALSE. Once started, the resolution continues until it is canceled by calling CFNetServiceCancel.

    When resolving a service that runs in synchronous mode, this function blocks until the CFNetService is updated with at least one IP address, until an error occurs, or until CFNetServiceCancel is called.

    Special Considerations

    This function is thread safe.

    If the service will be used in asynchronous mode, you must call CFNetServiceSetClient before calling this function.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Schedules a CFNetService on a run loop.

    Declaration

    Swift

    func CFNetServiceScheduleWithRunLoop(_ theService: CFNetService!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceScheduleWithRunLoop ( CFNetServiceRef theService, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    theService

    The CFNetService that is to be scheduled on a run loop; cannot be NULL.

    runLoop

    The run loop on which the service is to be scheduled; cannot be NULL.

    runLoopMode

    The mode on which to schedule the service; cannot be NULL.

    Discussion

    Schedules the specified service on a run loop, which places the service in asynchronous mode. The caller is responsible for ensuring that at least one of the run loops on which the service is scheduled is being run.

    Special Considerations

    This function is thread safe.

    Before calling this function, call CFNetServiceSetClient to prepare a CFNetService for use in asynchronous mode.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Associates a callback function with a CFNetService or disassociates a callback function from a CFNetService.

    Declaration

    Swift

    func CFNetServiceSetClient(_ theService: CFNetService!, _ clientCB: CFNetServiceClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Boolean

    Objective-C

    Boolean CFNetServiceSetClient ( CFNetServiceRef theService, CFNetServiceClientCallBack clientCB, CFNetServiceClientContext *clientContext );

    Parameters

    theService

    The CFNetService; cannot be NULL.

    clientCB

    The callback function that is to be associated with this CFNetService. If you are shutting down the service, set clientCB to NULL to disassociate from this CFNetService the callback function that was previously associated.

    clientContext

    Context information to be used when clientCB is called; cannot be NULL.

    Return Value

    TRUE if the client was set; otherwise, FALSE.

    Discussion

    The callback function specified by clientCB will be called to report IP addresses (in the case of CFNetServiceResolve) or to report registration errors (in the case of CFNetServiceRegister).

    Special Considerations

    This function is thread safe.

    For a CFNetService that will operate asynchronously, call this function and then call CFNetServiceScheduleWithRunLoop to schedule the service on a run loop. Then call CFNetServiceRegister or CFNetServiceResolve.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Sets the TXT record for a CFNetService.

    Declaration

    Swift

    func CFNetServiceSetTXTData(_ theService: CFNetService!, _ txtRecord: CFData!) -> Boolean

    Objective-C

    Boolean CFNetServiceSetTXTData ( CFNetServiceRef theService, CFDataRef txtRecord );

    Parameters

    theService

    CFNetServiceRef for which a TXT record is to be set; cannot be NULL.

    txtRecord

    Contents of the TXT record that is to be set. The contents must not exceed 1450 bytes.

    Return Value

    TRUE if the TXT record was set; otherwise, FALSE.

    Discussion

    This function sets a TXT record for the specified service. If the service is currently registered on the network, the record is broadcast. Setting a TXT record on a service that is still being resolved is not allowed.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Unschedules a CFNetService from a run loop.

    Declaration

    Swift

    func CFNetServiceUnscheduleFromRunLoop(_ theService: CFNetService!, _ runLoop: CFRunLoop!, _ runLoopMode: CFString!)

    Objective-C

    void CFNetServiceUnscheduleFromRunLoop ( CFNetServiceRef theService, CFRunLoopRef runLoop, CFStringRef runLoopMode );

    Parameters

    theService

    The CFNetService that is to be unscheduled; cannot be NULL.

    runLoop

    The run loop; cannot be NULL.

    runLoopMode

    The mode from which the service is to be unscheduled; cannot be NULL.

    Discussion

    Unschedules the specified service from the specified run loop and mode. Call this function to shut down a service that is running asynchronously. To complete the shutdown, call CFNetServiceSetClient and set clientCB to NULL. Then call CFNetServiceCancel.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the Core Foundation type identifier for the Network Service object.

    Declaration

    Swift

    func CFNetServiceGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFNetServiceGetTypeID ( void );

    Return Value

    The type ID.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the Core Foundation type identifier for all CFNetServiceMonitor instances.

    Declaration

    Swift

    func CFNetServiceMonitorGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFNetServiceMonitorGetTypeID ( void );

    Return Value

    The type ID.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Gets the Core Foundation type identifier for the Network Service browser object.

    Declaration

    Swift

    func CFNetServiceBrowserGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CFNetServiceBrowserGetTypeID ( void );

    Return Value

    The type ID.

    Special Considerations

    This function is thread safe.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

Callbacks

  • Defines a pointer to the callback function for a CFNetServiceBrowser.

    Declaration

    Swift

    typealias CFNetServiceBrowserClientCallBack = CFunctionPointer<((CFNetServiceBrowser!, CFOptionFlags, AnyObject!, UnsafeMutablePointer<CFStreamError>, UnsafeMutablePointer<Void>) -> Void)>

    Objective-C

    typedef void (*CFNetServiceBrowserClientCallBack) ( CFNetServiceBrowserRef browser, CFOptionFlags flags, CFTypeRef domainOrService, CFStreamError * error, void* info);

    Parameters

    browser

    The CFNetServiceBrowser associated with this callback function.

    flags

    Flags conveying additional information. The kCFNetServiceFlagIsDomain bit is set if domainOrService contains a domain; if this bit is not set, domainOrService contains a CFNetService instance. For additional bit values, see CFNetServiceBrowserClientCallBack Bit Flags.

    domainOrService

    A string containing a domain name if this callback function is being called as a result of calling CFNetServiceBrowserSearchForDomains, or a CFNetService instance if this callback function is being called as a result calling CFNetServiceBrowserSearchForServices.

    error

    A pointer to a CFStreamError structure whose error field may contain an error code.

    info

    User-defined context information. The value of info is the same as the value of the info field of the CFNetServiceClientContext structure that was provided when CFNetServiceBrowserCreate was called to create the CFNetServiceBrowser associated with this callback function.

    Discussion

    The callback function for a CFNetServiceBrowser is called one or more times when domains or services are found as the result of calling CFNetServiceBrowserSearchForDomains and CFNetServiceBrowserSearchForServices.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Defines a pointer to the callback function for a CFNetService.

    Declaration

    Swift

    typealias CFNetServiceClientCallBack = CFunctionPointer<((CFNetService!, UnsafeMutablePointer<CFStreamError>, UnsafeMutablePointer<Void>) -> Void)>

    Objective-C

    typedef void (*CFNetServiceClientCallBack) ( CFNetServiceRef theService, CFStreamError * error, void* info);

    Parameters

    theService

    CFNetService associated with this callback function.

    error

    Pointer to a CFStreamError structure whose error field contain may contain an error code.

    info

    User-defined context information. The value of info is the same as the value of the info field of the CFNetServiceClientContext structure that was provided when CFNetServiceSetClient was called for the CFNetService associated with this callback function.

    Discussion

    Your callback function will be called when there are results of resolving a CFNetService to report or when there are registration errors to report. In the case of resolution, if the service has more than one IP address, your callback will be called once for each address.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Defines a pointer to the callback function that is to be called when a monitored record type changes.

    Declaration

    Swift

    typealias CFNetServiceMonitorClientCallBack = CFunctionPointer<((CFNetServiceMonitor!, CFNetService!, CFNetServiceMonitorType, CFData!, UnsafeMutablePointer<CFStreamError>, UnsafeMutablePointer<Void>) -> Void)>

    Objective-C

    typedef void (*CFNetServiceMonitorClientCallBack) ( CFNetServiceMonitorRef theMonitor, CFNetServiceRef theService, CFNetServiceMonitorType typeInfo, CFDataRef rdata, CFStreamError * error, void* info);

    Parameters

    theMonitor

    CFNetServiceMonitor for which the callback is being called.

    theService

    CFNetService for which the callback is being called.

    typeInfo

    Type of record that changed. For possible values, see CFNetServiceMonitorType Constants.

    rdata

    Contents of the record that changed.

    error

    Pointer to CFStreamError structure whose error field contains an error code if an error occurred.

    info

    Arbitrary pointer to the user-defined data that was specified in the info field of the CFNetServiceClientContext structure when the monitor was created by CFNetServiceMonitorCreate.

    Discussion

    The callback function will be called when the monitored record type changes or when the monitor is stopped by calling CFNetServiceMonitorStop.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

Data Types

  • An opaque reference representing a CFNetServiceBrowser.

    Declaration

    Swift

    typealias CFNetServiceBrowserRef = CFNetServiceBrowser

    Objective-C

    typedef struct __CFNetServiceBrowser* CFNetServiceBrowserRef;

    Availability

    Available in iOS 2.0 and later.

  • A structure provided when a CFNetService is associated with a callback function or when a CFNetServiceBrowser is created.

    Declaration

    Swift

    struct CFNetServiceClientContext { var version: CFIndex var info: UnsafeMutablePointer<Void> var retain: CFAllocatorRetainCallBack var release: CFAllocatorReleaseCallBack var copyDescription: CFAllocatorCopyDescriptionCallBack init() init(version version: CFIndex, info info: UnsafeMutablePointer<Void>, retain retain: CFAllocatorRetainCallBack, release release: CFAllocatorReleaseCallBack, copyDescription copyDescription: CFAllocatorCopyDescriptionCallBack) }

    Objective-C

    struct CFNetServiceClientContext { CFIndex version; void *info; CFAllocatorRetainCallBack retain; CFAllocatorReleaseCallBack release; CFAllocatorCopyDescriptionCallBack copyDescription; }; typedef struct CFNetServiceClientContext CFNetServiceClientContext;

    Fields

    version

    Version number for this structure. Currently the only valid value is zero.

    info

    Arbitrary pointer to user-allocated memory containing user-defined data that is associated with the service, browser, or monitor and is passed to their respective callback functions. The data must be valid for as long as the CFNetService, CFNetServiceBrowser, or CFNetServiceMonitor is valid. Set this field to NULL if your callback function doesn’t want to receive user-defined data.

    retain

    The callback used to add a retain for the service or browser using info for the life of the service or browser. This callback may be used for temporary references the service or browser needs to take. This callback returns the actual info pointer so it can be stored in the service or browser. This field can be NULL.

    release

    Callback that removes a retain previously added for the service or browser on the info pointer. This field can be NULL, but setting this field to NULL may result in memory leaks.

    copyDescription

    Callback used to create a descriptive string representation of the data pointed to by info. In implementing this function, return a reference to a CFString object that describes your allocator and some characteristics of your user-defined data, which is used by CFCopyDescription(). You can set this field to NULL, in which case Core Foundation will provide a rudimentary description.

    Availability

    Available in iOS 2.0 and later.

  • An opaque reference for a service monitor.

    Declaration

    Swift

    typealias CFNetServiceMonitorRef = CFNetServiceMonitor

    Objective-C

    typedef struct __CFNetServiceMonitor* CFNetServiceMonitorRef;

    Discussion

    Service monitor references are used to monitor record changes on a CFNetServiceRef.

    Availability

    Available in iOS 2.0 and later.

  • An opaque reference representing a CFNetService.

    Declaration

    Swift

    typealias CFNetServiceRef = CFNetService

    Objective-C

    typedef struct __CFNetService* CFNetServiceRef;

    Availability

    Available in iOS 2.0 and later.

Constants

  • Bit flags used when registering a service.

    Declaration

    Swift

    static var FlagNoAutoRename: CFNetServiceRegisterFlags { get }

    Objective-C

    enum { kCFNetServiceFlagNoAutoRename = 1 };

    Constants

    • FlagNoAutoRename

      kCFNetServiceFlagNoAutoRename

      Causes registrations to fail if a name conflict occurs.

      Available in iOS 2.0 and later.

  • Bit flags providing additional information about the result returned when a client’s CFNetServiceBrowserClientCallBack function is called.

    Declaration

    Swift

    static var MoreComing: CFNetServiceBrowserFlags { get } static var IsDomain: CFNetServiceBrowserFlags { get } static var IsDefault: CFNetServiceBrowserFlags { get } static var Remove: CFNetServiceBrowserFlags { get }

    Objective-C

    enum { kCFNetServiceFlagMoreComing = 1, kCFNetServiceFlagIsDomain = 2, kCFNetServiceFlagIsDefault = 4, kCFNetServiceFlagIsRegistrationDomain = 4, /* For compatibility */ kCFNetServiceFlagRemove = 8 };

    Constants

    • MoreComing

      kCFNetServiceFlagMoreComing

      If set, a hint that the client’s callback function will be called again soon; therefore, the client should not do anything time-consuming, such as updating the screen.

      Available in iOS 2.0 and later.

    • IsDomain

      kCFNetServiceFlagIsDomain

      If set, the results pertain to a search for domains. If not set, the results pertain to a search for services.

      Available in iOS 2.0 and later.

    • IsDefault

      kCFNetServiceFlagIsDefault

      If set, the resulting domain is the default registration or browse domain, depending on the context. For this version of the CFNetServices API, the default registration domain is the local domain. In previous versions of this API, this constant was kCFNetServiceFlagIsRegistrationDomain, which is retained for backward compatibility.

      Available in iOS 2.0 and later.

    • Remove

      kCFNetServiceFlagRemove

      If set, the client should remove the result item instead of adding it.

      Available in iOS 2.0 and later.

    Discussion

    See CFNetServiceBrowserClientCallBack for additional information.

  • Record type specifier used to tell a service monitor the type of record changes to watch for.

    Declaration

    Swift

    enum CFNetServiceMonitorType : Int32 { case TXT }

    Objective-C

    enum { kCFNetServiceMonitorTXT = 1 } typedef enum CFNetServiceMonitorType CFNetServiceMonitorType;

    Constants

    • TXT

      kCFNetServiceMonitorTXT

      Watch for TXT record changes.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Error codes that may be returned by CFNetServices functions or passed to CFNetServices callback functions.

    Declaration

    Swift

    enum CFNetServicesError : Int32 { case Unknown case Collision case NotFound case InProgress case BadArgument case Cancel case Invalid case Timeout }

    Objective-C

    typedef enum { kCFNetServicesErrorUnknown = -72000, kCFNetServicesErrorCollision = -72001, kCFNetServicesErrorNotFound = -72002, kCFNetServicesErrorInProgress = -72003, kCFNetServicesErrorBadArgument = -72004, kCFNetServicesErrorCancel = -72005, kCFNetServicesErrorInvalid = -72006, kCFNetServicesErrorTimeout = -72007 } CFNetServicesError;

    Constants

    • Unknown

      kCFNetServicesErrorUnknown

      An unknown CFNetService error occurred.

      Available in iOS 2.0 and later.

    • Collision

      kCFNetServicesErrorCollision

      An attempt was made to use a name that is already in use.

      Available in iOS 2.0 and later.

    • NotFound

      kCFNetServicesErrorNotFound

      Not used.

      Available in iOS 2.0 and later.

    • InProgress

      kCFNetServicesErrorInProgress

      A search is already in progress.

      Available in iOS 2.0 and later.

    • BadArgument

      kCFNetServicesErrorBadArgument

      A required argument was not provided.

      Available in iOS 2.0 and later.

    • Cancel

      kCFNetServicesErrorCancel

      The search or service was canceled.

      Available in iOS 2.0 and later.

    • Invalid

      kCFNetServicesErrorInvalid

      Invalid data was passed to a CFNetServices function.

      Available in iOS 2.0 and later.

    • Timeout

      kCFNetServicesErrorTimeout

      Resolution failed because the timeout was reached.

      Available in iOS 2.0 and later.

    Import Statement

    Objective-C

    @import CFNetwork;

    Swift

    import CFNetwork

    Availability

    Available in iOS 2.0 and later.

  • Error domains.

    Declaration

    Swift

    let kCFStreamErrorDomainMach: Int32 let kCFStreamErrorDomainNetServices: Int32

    Objective-C

    extern const SInt32 kCFStreamErrorDomainMach; extern const SInt32 kCFStreamErrorDomainNetServices;

    Constants

    • kCFStreamErrorDomainMach

      kCFStreamErrorDomainMach

      Error domain returning errors reported by Mach. For more information, see the header file /usr/include/mach/error.h.

      Available in iOS 2.0 and later.

    • kCFStreamErrorDomainNetServices

      kCFStreamErrorDomainNetServices

      Error domain returning errors reported by the service discovery APIs. These errors are only returned if you use the CFNetServiceBrowser API or any APIs introduced in OS X v10.4 or later.

      Available in iOS 2.0 and later.