ios - 应用程序进入后台时 GCDWebServer 崩溃
<p><p>当我的应用程序进入后台时,我的 GCDWebServer (3.3.3) 崩溃了:</p>
<pre><code>#30x000000010041ea80 in - at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:221
#40x00000001004248b8 in __destroy_helper_block_ ()
#50x000000018dd52a28 in _Block_release ()
#60x00000001020ad21c in _dispatch_client_callout ()
#70x00000001020b2284 in _dispatch_main_queue_callback_4CF ()
#80x000000018ee21f2c in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#90x000000018ee1fb18 in __CFRunLoopRun ()
#10 0x000000018ed4e048 in CFRunLoopRunSpecific ()
#11 0x00000001907d1198 in GSEventRunModal ()
#12 0x0000000194d28628 in - ()
#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)
#00x00000001020b8ba4 in _dispatch_queue_push ()
#10x0000000100424680 in - at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:734
#20x0000000100424a10 in - at project/Pods/GCDWebServer/GCDWebServer/Core/GCDWebServer.m:746
</code></pre>
<p>具体行是:</p>
<pre><code>GWS_DCHECK(_options == nil);// The server can never be dealloc'ed while running because of the retain-cycle with the dispatch source
</code></pre>
<p>看起来 <code>_options</code> 字典必须为 nil(例如,服务器必须停止)但看起来 <code>_options</code> 从未设置为 <code>此代码路径上的 nil</code>:它在 <code>-stop</code> 中设置为 nil,但在 <code>-_stop</code> 中未设置。</p>
<p>我可能遗漏了一些东西,因为这会被其他人注意到。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我遇到了同样的问题。我解决了将服务器保存在我的类的静态变量中而不是保存在函数中的问题。 </p>
<p>它不起作用:</p>
<pre><code> class Server {
static func initialize() {
let webServer = GCDWebServer()
...
webServer?.start(withPort: 8081, bonjourName: nil)
}
}
</code></pre>
<p>有效:</p>
<pre><code> class Server {
static let webServer = GCDWebServer()
static func initialize() {
...
webServer?.start(withPort: 8081, bonjourName: nil)
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 应用程序进入后台时 GCDWebServer 崩溃,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39870455/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39870455/
</a>
</p>
页:
[1]