I am using a URLSessionWebSocketTask. When trying to receive messages while the app is backgrounded, the receive()
method fails with an NSError
where the domain is NSPOSIXErrorDomain
and the code is ECONNABORTED
. That behavior is good. However, when this happens, the URLSessionWebSocketTask reports a closeCode of invalid
, which is supposed to denote that the connection is still open. However, the connection state
property is reporting completed
. I feel that the closeCode
property should be reporting something like abnormalClosure
in this case. Either way, this seems like a bug or the documentation is incorrect.
Either way, this seems like a bug or the documentation is incorrect.
And the best path forward is to file a bug explaining your concern. The URLSession
engineering team can make a determination as to what the expected behaviour is and, if necessary, route your bug to docs folks.
Please post your bug number, just for the record.
But in this case I suspect that your best path forward is actually to not use URLSession
for WebSocket, but instead use Network framework. See TN3151 Choosing the right networking API.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"