10

I have a problem when loading the local web from WKWebView in iOS8. There are some suggestions that I should use GCDWebServer. I read through GCDWebServer, but not really understand what GCDWebServer is for on mobile application's side.

Could you give me any practical case of using this library? Sorry for my ignorance.

Pol
  • 3,848
  • 1
  • 38
  • 55
chipbk10
  • 5,783
  • 12
  • 49
  • 85

2 Answers2

13

It's a webserver that you can run on your iOS device. Just like you would run a webserver on VPS or dedicated server providers.

This webserver that you would run and host from your iOS app will of course be available only in the network your iOS device is connected to.

This makes it useful for you to write client programs or scripts on other machines but connected to that network, to call your iOS app (running the GCDWebServer) to upload or download files that you so choose to store in your iOS app's sandboxes document directory for instance. Or as simple as viewing HTML or other data - plain text or json - served by GCDWebServer.

It had nothing to do with what WKWebView. WKWebView is a 'simplified WebKit browser client' that you can implement in your iOS app to view web pages served from other webserver hosts.

You can think of WKWebView as the complete opposite of GCDWebServer.

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
  • "be useful when we write client programs or scripts on other machines but connected to that network". What are the clients programs here? You mean other iOS applications on the same device (iPhone or iPad) ? – chipbk10 Mar 30 '15 at 12:37
  • 1
    For instance, I am currently writing a desktop app (on windows machine) that can retrieve files from my iOS app. In this context, the desktop app is the client program and my iOS app running GCDWebServer is the server in the local network that both my desktop machine and my iOS device are connected to. – Calvin Cheng Mar 30 '15 at 13:28
  • it's funny that iOS app plays as the server's role. – chipbk10 Mar 30 '15 at 13:44
  • 3
    A program is just a program. If we implement webserver functionality in that program, it can act as a server. If that same program has a client functionality to grab stuff from a server, it can act as a client too. We can design our programs to be a client OR a server OR a client AND server. :-) – Calvin Cheng Mar 30 '15 at 13:55
  • Hi Calvin, I noticed in your comments you mentioned that you are writing a desktop app to act as a client for GCDWebserver. I am also interested in creating something similar, would you be willing to perhaps share some code or help to point me in the right direction. I've never developed for windows desktop before... – Shayno Jun 22 '17 at 22:45
2

We can use GCDWebServer has a network interceptor in ios. You can intercept any HTTP requests happening inside WKWebView. For example, you can use GCDWebServer to handle caching and parallel processing for your expensive API requests. You can immediately return some cached responses and later redirect the URL to the actual destination.

Vinay Hosamane
  • 346
  • 1
  • 5
  • 15