A URL session task that communicates over the WebSockets protocol standard.
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
NSURLSession is a concrete subclass of
NSURLSession that provides a message-oriented transport protocol over TCP and TLS in the form of WebSocket framing. It follows the WebSocket Protocol defined in RFC 6455.
You create a
NSURLSession with either a
wss: URL. When creating the task, you can also provide a list of protocols to advertise during the handshake phase. Once the handshake completes, your app receives notifications through the session’s
You send data with
send and receive data with
receive. The task performs reads and writes asynchronously, and allows you to send and receive messages that contain both binary frames and UTF-8 encoded text frames. The task enqueues any reads or writes you perform prior to the handshake’s completion, and executes them after the handshake completes.
NSURLSession supports redirection and authentication like other types of tasks do, using the methods in
NSURLSession. The WebSocket task calls the redirection and authentication delegate methods prior to completing the handshake. The WebSocket task also supports cookies, by storing cookies to the session configuration’s
HTTPCookie, and attaches cookies to outgoing HTTP handshake requests.