I'm using GCDWebservers to start a http service. I want it still accept connections in background mode. This is my source code:
func startServer (){
do {
webServer?.stop()
webServer?.removeAllHandlers()
try self.webServer?.start(options: [GCDWebServerOption_BonjourName: "", GCDWebServerOption_BonjourType: IMS_DOMAIN, GCDWebServerOption_Port : IMS_SERVICE_PORT, GCDWebServerOption_AutomaticallySuspendInBackground: false])
} catch {
print("Start server error: ", error.localizedDescription)
}
print("bonjour type", self.webServer?.bonjourType)
}
It works on simulator but on real device its not working. This message printout when App goes foreground again:
dnssd_clientstub read_all(10) DEFUNCT
[ERROR] Bonjour registration error -72000 (domain 10)
Please help me.
It's not possible to run a web server while your app is in the background (except for the first few minutes at most). See the "GCDWebServer & Background Mode for iOS Apps" section in the GCDWebServer README
file for the detailed information:
Typically you must stop any network servers while the app is in the background and restart them when the app comes back to the foreground.