当我的应用程序进入后台时,我从GCDWebServer(3.3.3)崩溃了:
NSString *pathForFile = [[NSBundle mainBundle] pathForResource: @"splash" ofType: @"gif"];
NSData *dataOfGif = [NSData dataWithContentsOfFile: pathForFile];
UIWebView *Web_View = [[UIWebView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[Web_View loadData:dataOfGif MIMEType:@"image/gif" textEncodingName:@"" baseURL:[NSURL URLWithString:@""]];
[self.view addSubview:Web_View];
具体行是:
#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
字典必须为nil(例如,必须停止服务器)但看起来_options
在此代码路径上永远不会设置为_options
:它在nil
中设置为nil,但在- stop
中设置为nil。
我可能会遗漏一些东西,因为其他人会注意到这一点。
答案 0 :(得分:2)
我遇到了同样的问题。我解决了它将服务器保存在我的类中的静态变量而不是保存在函数中。
它不起作用:
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)
}
}