使应用程序充当服务器

时间:2014-02-26 10:19:18

标签: ios iphone cocoahttpserver

我正在使用CocoaHTTPServer,我可以启动服务器。在我的资源文件夹中,我添加了一个名为“index.html”的文件,这里让我感到困惑。

  • 我可以通过

    获取索引文件的路径

    [mainbundle    pathForResource:@“index”ofType:@“html”]

    但它给了我一条道路 /Users/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/。 有没有办法让路径成为一个网络网址 http://127.0.0.1:56000/user/library/.../index.html"将其加载到 UIWebView中。

  • 我想获取上面格式的文件路径,因为我想 当UIWebView请求它时以及应用程序何时捕获 响应。

我有什么方法可以实现吗? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

  1. 您可以将资源加载到UIWebView这样的

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
    
  2. 要了解UIWebView的请求,请检查UIWebViewDelegate协议here。您可以使用以下方法,例如webView:shouldStartLoadWithRequest:navigationType:

相关问题