我正在使用 CocoaHTTPServer
,并且我能够启动服务器。在我的资源文件夹中,我添加了一个名为“index.html”的文件,这让我感到困惑。
我可以通过
获取索引文件的路径[主包 pathForResource:@"index"ofType:@"html"]
但它给了我路径
/Users/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/
。 有什么方法可以让路径变成像这样的web-urlhttp://127.0.0.1:56000/user/library/.../index.html"
将其加载到 UIWebView。- 我想获取像上面格式的文件路径,因为我想 当 UIWebView 向它发出请求时捕获以及应用程序何时会捕获 回应。
有什么办法可以实现吗?? 提前致谢。
最佳答案
您可以像这样将资源加载到
UIWebView
中NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]]; [webview loadRequest:[NSURLRequest requestWithURL:url]];
要捕获
UIWebView
的请求,请检查UIWebViewDelegate
协议(protocol)here .您可以尝试使用以下方法,例如webView:shouldStartLoadWithRequest:navigationType:
关于ios - 让应用程序充当服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22038273/