ios - 应用程序进入后台时 GCDWebServer 崩溃

标签 ios cocoa-touch crash background-process 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 中未设置。

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

最佳答案

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

它不起作用:

    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/

相关文章:

android - 仅某些设备中的Android/NDK SIGILL错误

ios - 自定义 UIView 使用 init(coder) 初始化,如何使用 init(frame) 初始化它

ios - UITableview 滚动改变图像,UITableview 滚动问题

ios - NSAttributedString 如何遵循 MVC 范式?

ios - 将 AVPlayerLayer 添加到 UIViewController

ios - 尝试替换NSString中的字符串的许多实例时,内存使用过多

android - 在 Android 上使用 ClassNotFoundException 首次打开时 Flutter 应用程序崩溃

ios - 每次应用重新启动时我都应该调用 setMinimumBackgroundFetchInterval 吗?

iphone - 通过 SQLite 将核心数据与 SQL 或 MySQL 同步

crash - rapidJson:在 Release模式下崩溃