HomeiOS Developmentios - How one can maintain websocket connection whereas coming into background...

ios – How one can maintain websocket connection whereas coming into background in swift?


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 maintain connection even when it enters the background.

   non-public 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 maintain connection even when it enters the background.

Is there any technique to maintain the connection alive?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments