swisspol/GCDWebServer

Crashing when initializing GCDWebServer(), except while XCode debugger is attached...?

jnicholls opened this issue · 1 comments

I have a pretty odd issue occurring right now. Below is the AppDelegate code (the relevant parts):

import GCDWebServers
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var webserver: GCDWebServer?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        webserver = GCDWebServer()

        webserver?.addDefaultHandler(forMethod: "GET", request: GCDWebServerRequest.self, asyncProcessBlock: {request, completion in
            let time = DispatchTime.now() + .seconds(1)
            DispatchQueue.global(qos: .background).asyncAfter(deadline: time) {
//                let response = GCDWebServerResponse(redirect: URL(string: "https://www.google.com")!, permanent: false)
                let response = GCDWebServerDataResponse(jsonObject: ["redirect_uri": "https://www.google.com"])
                completion(response)
            }
        })

        do {
            try webserver?.start(options: [GCDWebServerOption_AutomaticallySuspendInBackground: false, GCDWebServerOption_Port: 25519, GCDWebServerOption_BindToLocalhost: true])
        } catch {

        }
        
        return true
    }
}

This code runs fine and the web server responds appropriately when the app is launched from XCode with the debugger attached. However, when I run the app fresh within the simulator (tap on icon to launch) it immediately crashes. I narrowed it down to this line:

webserver = GCDWebServer()

For some reason, just initializing the web server instance is causing the app to crash. Any thoughts?

Thanks in advance!

This was due to not copying in the GCDWebServer framework into the final bundle. I was getting a dyld error.