GCDWebservers 后台模式无法在设备上运行

GCDWebservers background mode not working on device

我正在使用 GCDWebservers 启动 http 服务。我希望它仍然在后台模式下接受连接。这是我的源代码:

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)
}

它在模拟器上工作,但在真实设备上不工作。当 App 再次进入前台时打印出此消息:

dnssd_clientstub read_all(10) DEFUNCT

[ERROR] Bonjour registration error -72000 (domain 10)

请帮帮我

无法在您的应用程序处于后台时 运行 Web 服务器(最多前几分钟除外)。有关详细信息,请参阅 GCDWebServer README 文件中的 "GCDWebServer & Background Mode for iOS Apps" 部分:

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.