i am implementing real-time chat utilizing websocket protocol.
It makes use of the apple websocket framework to maintain the reference to the server,
however when it enters the background, the connection is disconnected.
I need to hold connection even when it enters the background.
personal var websocket: URLSessionWebSocketTask?
func connectWebsocket() {
let session = URLSession(
configuration: .default,
delegate: self,
delegateQueue: OperationQueue()
)
let url = URL(string: "ws://URL...")
webSocket = session.webSocketTask(with: url)
webSocket?.resume()
}
I need to hold connection even when it enters the background.
Is there any strategy to hold the connection alive?