Skip to content

MASTG-KNOW-0073: iOS Network APIs

On iOS, you can create network connections through multiple API layers. These layers differ in abstraction level, supported protocols, and how much of the connection lifecycle they manage. See "TN3151: Choosing the right networking API" for advice on selecting the appropriate API for your use case.

URL Loading System (High-Level)

The URL Loading System is the highest-level networking stack in Foundation. It is the primary API surface for HTTP and HTTPS.

Common APIs in this layer include:

URLSession supports a broad set of HTTP features (for example redirects, caching, cookies, and proxies) and integrates with the system trust store and server trust evaluation ( Server Trust Evaluation). See this example of use for "Fetching website data into memory" from the official Apple documentation.

Network Framework (Low-Level)

The Network framework, introduced in iOS 12, provides direct access to protocols like TLS, TCP and UDP. It exposes connection and listener primitives and lets you configure transports and protocol stacks explicitly. See the WWDC2018 session "Introducing Network.framework: A modern alternative to Sockets" for an overview.

Common APIs in this layer include:

See this example of use for "Implementing netcat with Network Framework" from the official Apple documentation.

In iOS 26 the framework adds new Swift structured concurrency oriented APIs that provide a modern, declarative interface for connections, listeners, and endpoint discovery. See the WWDC2025 session "Use structured concurrency with Network framework" for details. These APIs include:

Apple advises developers to keep using the URL Loading System for HTTP- and URL-based networking. Use the Network framework only when you need lower-level access to protocols or custom transports not supported by the URL Loading System.

CFNetwork and Core Foundation Streams (Low-Level)

CFNetwork is a lower-level networking framework that provides Core Foundation APIs and stream abstractions.

Common APIs in this layer include:

You may encounter CFNetwork-based networking both in apps and in third-party libraries, especially where a C or Core Foundation interface is preferred.

Apple's archived documentation is available at "Using Sockets and Socket Streams".

BSD Sockets (Lowest-Level)

At the lowest level, iOS supports POSIX/BSD socket APIs for TCP and UDP.

Common functions include:

Relationship to App Transport Security (ATS)

App Transport Security (ATS) is enforced for connections made through the URL Loading System. Lower-level APIs (such as Network framework, CFNetwork/Core Foundation streams, and BSD sockets) are outside the scope of ATS enforcement.

For details about ATS behavior and configuration, see iOS App Transport Security.