OStack程序员社区-中国程序员成长平台

标题: ios - 应用程序进入后台时 GCDWebServer 崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:14
标题: ios - 应用程序进入后台时 GCDWebServer 崩溃

当我的应用程序进入后台时,我的 GCDWebServer (3.3.3) 崩溃了:

#3  0x000000010041ea80 in -[GCDWebServer dealloc] at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:221
#4  0x00000001004248b8 in __destroy_helper_block_ ()
#5  0x000000018dd52a28 in _Block_release ()
#6  0x00000001020ad21c in _dispatch_client_callout ()
#7  0x00000001020b2284 in _dispatch_main_queue_callback_4CF ()
#8  0x000000018ee21f2c in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#9  0x000000018ee1fb18 in __CFRunLoopRun ()
#10 0x000000018ed4e048 in CFRunLoopRunSpecific ()
#11 0x00000001907d1198 in GSEventRunModal ()
#12 0x0000000194d28628 in -[UIApplication _run] ()
#13 0x0000000194d23360 in UIApplicationMain ()
#14 0x000000010009243c in main at project/main.m:10
#15 0x000000018dd305b8 in start ()
Enqueued from com.apple.main-thread (Thread 1)Queue : com.apple.main-thread (serial)
#0  0x00000001020b8ba4 in _dispatch_queue_push ()
#1  0x0000000100424680 in -[GCDWebServer _stop] at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:734
#2  0x0000000100424a10 in -[GCDWebServer _didEnterBackground:] at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:746

具体行是:

GWS_DCHECK(_options == nil);  // The server can never be dealloc'ed while running because of the retain-cycle with the dispatch source

看起来 _options 字典必须为 nil(例如,服务器必须停止)但看起来 _options 从未设置为 此代码路径上的 nil:它在 -stop 中设置为 nil,但在 -_stop 中未设置。

我可能遗漏了一些东西,因为这会被其他人注意到。



Best Answer-推荐答案


我遇到了同样的问题。我解决了将服务器保存在我的类的静态变量中而不是保存在函数中的问题。

它不起作用:

    class Server {
        static func initialize() {
            let webServer = GCDWebServer()
            ...
            webServer?.start(withPort: 8081, bonjourName: nil)
        }
    }

有效:

    class Server {
        static let webServer = GCDWebServer()
        static func initialize() {
            ...
            webServer?.start(withPort: 8081, bonjourName: nil)
        }
    }

关于ios - 应用程序进入后台时 GCDWebServer 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39870455/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4