我正在使用 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)
}
它可以在模拟器上运行,但在真实设备上无法运行。当应用程序再次进入前台时打印此消息:
dnssd_clientstub read_all(10) DEFUNCT
[ERROR] Bonjour registration error -72000 (domain 10)
请帮助我。
最佳答案
当您的应用程序处于后台时(最多前几分钟除外),无法运行网络服务器。有关详细信息,请参阅 GCDWebServer README
文件中的“GCDWebServer 和 iOS 应用程序的后台模式”部分:
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.
关于ios - GCDWebservers 后台模式无法在设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40011679/