iosswiftswift3gcdwebserver

Get the Bonjour URL from GCDWebServer


I am using GCDWebServer and starting it by running:

webServer!.start(withPort: 8080, bonjourName: "Test")

When checking the [INFO] logs from GCDWebServer, I can see two messages in two distinct spots:

I am consufed by the fact that the other URL uses the device name and not the bonjourName I configured in the code above, but it's not a big deal.

What is a bigger deal is that after implementing the GCDWebServerDelegate's webServerDidStart, printing serverURL from there still shows the IP URL.

I can also see that webServerDidStart is invoked before I get the Bonjour registration complete for GCDWebServer message in the log.

How can I get the human-readable URL?


Solution

  • The property to use is bonjourServerURL. serverURL is always the IP address and once webServerDidCompleteBonjourRegistration delegate method is called, bonjourServerURL holds the value. I don't know why the host name in the Bonjour URL doesn't match the bonjourName argument value.