About NSNetServices and CFNetServices

The NSNetService class and the CFNetServices C API provide high-level abstractions for advertising, browsing, discovering, and resolving Bonjour services. After publishing or discovering a service, your app is responsible for providing networking code to do the actual communication.

Art/cocoa_06apilayer_2x.png

At a Glance

Both the NSNetService class and the CFNetServices C API are based on run loops, and can be integrated with your own networking code written using CFNetwork or Foundation networking APIs.

The NSNetService class is a Cocoa class that provides easy integration with GUI apps, Foundation run loops, and the NSStream family of networking classes. If you are writing Bonjour code to interface with code at this level, you should generally use the NSNetService class.

The CFNetServices API (described in CFNetServices Reference) is a CFNetwork-based class that provides easy integration with the CFNetwork family of networking APIs. If you are writing Bonjour code to interface with Core Foundation–level code, you can use either the CFNetServices API or the NSNetService class.

How to Use This Document

Whether you want to use the NSNetService class or the CFNetServices API, read Foundation Network Services Architecture to gain an understanding of the Foundation classes available. These Foundation classes map fairly neatly onto CFNetServices opaque types; only the names and calling conventions differ.

Next, decide what Bonjour tasks your app needs to perform and read the appropriate chapter or chapters for the Foundation-level API (even if you intend to use the CFNetServices API). These chapters provide conceptual information about how to perform each task, along with code snippets based on the Foundation-level API.

Next, if you want to use the lower-level CFNetwork-based API, read Using CFNetServices, which provides code snippets that show you how to do so.

Finally, if you want to provide additional user control over which domains your app uses when browsing for or advertising services, read the appendix, Browsing for Domains.

Prerequisites

This document assumes that you are familiar with Bonjour, and have already read Bonjour Overview. This document also assumes that you are familiar with OS X and iOS networking as a whole, including the concepts described in Networking Overview.