Unable to create URLSessionWebSocketTask with background configuration

650 Views Asked by At

error: Execution was interrupted, reason: signal SIGABRT. The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

I'm trying to create URLSessionWebSocketTask with backdround configuration in Playground, but unfortunately i'm getting above mentioned error

import Foundation

let urlSession = URLSession(configuration: .background(withIdentifier: "___ID___"))
let webSocketTask = urlSession.webSocketTask(with: URL(string: "wss://echo.websocket.org")!)
1

There are 1 best solutions below

0
On

I get it,

https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background

Comply with Background Transfer Limitations

With background sessions, the actual transfer is performed by a process that is separate from your app’s process. Because restarting your app’s process is fairly expensive, a few features are unavailable, resulting in the following limitations:

  • The session must provide a delegate for event delivery. (For uploads and downloads, the delegates behave the same as for in-process transfers.)

  • Only HTTP and HTTPS protocols are supported (no custom protocols).

  • Redirects are always followed. As a result, even if you have implemented urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:), it is not called.

  • Only upload tasks from a file are supported (uploads from data instances or a stream fail after the app exits).