Instance Method

URLSession:webSocketTask:didOpenWithProtocol:

Tells the delegate that the WebSocket task successfully negotiated the handshake with the endpoint, indicating the negotiated protocol.

Declaration

- (void)URLSession:(NSURLSession *)session webSocketTask:(NSURLSessionWebSocketTask *)webSocketTask didOpenWithProtocol:(NSString *)protocol;

Parameters

session

The session of the WebSocket task that opened.

webSocketTask

The WebSocket task that opened.

protocol

The protocol picked during the handshake phase. This parameter is nil if the server did not pick a protocol, or if the client did not advertise protocols when creating the task.

Discussion

If the handshake fails, the task doesn’t call this delegate method.

See Also

Handling WebSocket Lifecycle Events

- URLSession:webSocketTask:didCloseWithCode:reason:

Tells the delegate that the WebSocket task received a close frame from the server endpoint, optionally including a close code and reason from the server.