Make app act as a Server

265 Views Asked by At

I'm using CocoaHTTPServer, and I'm able to start the server. In my resources folder, I added a file called "index.html", and here is something that made me confused.

  • I can get the path of the index file by

    [mainbundle pathForResource:@"index" ofType:@"html"]

    but it gave me the path as /Users/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/. Is there any way to make the path become a web-url like http://127.0.0.1:56000/user/library/.../index.html" to load it on an UIWebView.

  • I want to get the file path like the format above because I want to catch when the UIWebView request to it and when will the app response.

Is there any way for me to achieve it?? Thanks in advance.

1

There are 1 best solutions below

10
deimus On
  1. You can load a resource into a UIWebView like this

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
    
  2. For catching the requests of a UIWebView please check UIWebViewDelegate protocol here. You can play around with following method for example webView:shouldStartLoadWithRequest:navigationType: