Creates a WebSocket task for the provided URL request.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
Framework
- Foundation
Declaration
- (NSURLSession Web Socket Task *)webSocketTaskWithRequest:(NSURLRequest *)request;
Parameters
request
A URL request that indicates a WebSockets endpoint with which to connect.
Discussion
You can modify the request’s properties prior to calling resume
on the task. The task uses these properties during the HTTP handshake phase.
To add custom protocols, add a header with the key Sec-Web
, and a comma-separated list of protocols you want to negotiate with the server. The custom HTTP headers provided by the client remain unchanged for the handshake with the server.