What is GCDWebServer for? - ios

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.

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.

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.

Related

iOS local HTTP server clear communication

I'm using GCDWebServer as a local HTTP server, serving data.
Another part of my application base on a WKWebView consume this data.
So while the data is travelling between the two, it's unencrypted and available to anyone (correct me if I'm wrong)? How dangerous would that be, on a non jailbroken iOS device?
Problem:
GCDWebServer doesn't support HTTPS : "What's not supported (but not really required from an embedded HTTP server): - HTTPS / - Keep Alive"
WKWebViews doesn't allow you to intercept incoming data for pre-treatment. "WKWebView makes requests and renders content out-of-process, meaning your app does not hear the requests they make"
Any solution other than picking a new local WebServer?

What is advantage of embedding HTTP server in iOS app?

In linked in implementation, they have HTTP server implemented in iOS app. What could be the reason behind this architecture, if uiwebview already handles the HTML loading and rendering.
I don't think they have a HTTP server embedded as much as they are just making very liberal use of UIWebView and the features of HTML5.
And the benefits of doing this are that they only have to write a relatively general implementation of the LinkedIn mobile interface in HTML5 and those changes get carried across to iOS, Android, Windows Mobile, and whatever other mobile platforms support HTML5.
I have a couple of apps with an embedded HTTP server. This is used as one possible method for importing/exporting data to/from the app. The user connects to the app from their computer's web browser to the server on their iOS device. The user can then download a file from or upload a file to the app. I added this feature before iOS supported file sharing via iTunes and the Documents directory. It's now one of several ways to get data to/from the app.

View local html/js contents in mobile safari

I need to view some local (saved somewhere in the iPad) html / js contents with mobile Safari. By reading some threads it seems that the file:// protocol is disabled. Right?
If so, the solution I see is to install an app which turns the iPad into an http server (no need for support of php or anything else), load my contents there and access somehow them within the same device by http://localhost/... or http://127.0.0.1/... with mobile safari.
Is that actually possible? Can someone please suggest me a good web server app which possibly does not require jailbrake or other hacking?
Thanks!
You probably can't do what you want because in order for your application to be serving up HTTP requests to Mobile Safari, it would have to be running in the background, and there's no permissible background mode that covers this.
If you only need a one-time-only response immediately after running your application, then you could possibly use beginBackgroundTaskWithExpirationHandler:, although this might not be approved by Apple - it's difficult to predict their response to that.
If you are sure that you don't need this to go into the App Store, then you can get your application running in the background permanently by abusing one of the other background modes, such as pretending to be a VOIP app or media player.
Once you're running in the background, you can use CocoaHTTPServer to actually serve the files.
If you describe what you are trying to achieve, somebody might be able to suggest an alternative approach to using local files / Mobile Safari.

inspect http requests in ios simulator/devices

I am working on an ios app which communicate with the server via http request. And I want to monitor the network traffic when testing my app in ios simulator/devices.
Is there any software or tools I can used to inspect the http requests of a specified application on mac/ios, just like firebugs for web developers?
Thanks.
As far as I know, there are several tools in App Store that provide the network traffic monitor feature. But, they could only view iPhone as a whole and stay at that level. In other words, they could only tell how much traffic has been consumed of this iPhone. For each app? No data.
You can use HTTP Catcher to capture web traffic. It's a Web debugging proxy for iOS, so you can view requests and responses directly on iPhone.
You can use Proxyman to record/capture all the requests & responses from your app while developing.It will support ios simulators also. Without doing any code change we use this.
First Download the Proxyman app form the above link after that just go through this documentation for references.
Charles has recently released an iOS version for http traffic monitoring. it is a paid app though. Good news is that you can set up Charles free desktop version then setup HTTP proxy from your iOS device.

how to implement a server on iPhone

Assuming I have implement that :
making my app as a server which means in safari I can connect to the app if I input http://url-link.
My question is : if I request http:// url-link/doc, and the server - that is my app can return the content in document directory.
I don't know how to write the web service in iPhone.
As I'm fresh to web service, can any one help me?
thanks
This is one possibility: Cocoa HTTP Server. From the project's page:
So with Apple's framework for an HTTP
server tucked under our arm we set out
to make our own. We wanted the
following:
Built in support for bonjour broadcasting
IPv4 and IPv6 support
Asynchronous networking using standard Cocoa sockets/streams
Digest access authentication
TLS encryption support
Extremely FAST and memory efficient
Heavily commented code
Very easily extensible
You can link this library from your app and effectively make it a mini-web server.

Resources