Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

how to set both protocols and `URLRequest` to `NSURLSessionWebSocketTask`

Hi there.

How can I do for the title?

URLRequest seems not to have property for protocols.

NSURLSessionWebSocketTask seems to have either URLRequest or protocols, but have neither of them.

What I want to do is setting both protocols and headers when using WebSocket.

Should I use Network.framework instead?

Answered by DTS Engineer in 839690022
Should I use Network framework instead?

Yes. That is, in fact, the advice we give in TN3151 Choosing the right networking API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Should I use Network framework instead?

Yes. That is, in fact, the advice we give in TN3151 Choosing the right networking API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Creating a WebSocketTask with protocols is just a convenience for setting the Sec-WebSocket-Protocol header field on the request. If you use the request based method, you can manually set the header field.

how to set both protocols and `URLRequest` to `NSURLSessionWebSocketTask`
 
 
Q