Does a background thread only work when the app in on top in IOS swift?

I have a websocket server which executed on a background thread like this:

DispatchQueue.global(qos: .userInteractive).async {
    let server = SecondServer()
    server.run()
}

But there is a problem. websocket server only responds to client commands when the app is on top. for example, when I run browser and send websocket command, the server doesn't respond until I bring my app on top. Is there any solution to help me that I can run my server on the background and my app doesn't need to be on top?

Does a background thread only work when the app in on top in IOS swift?
 
 
Q