【问题标题】:How to load FilePath into UIWebbview in iOS?如何在 iOS 中将文件路径加载到 UIWebview 中?
【发布时间】:2014-09-06 23:26:13
【问题描述】:
我想加载我保存在 Core Data 中的 html 文件。
它在 NSString 中得到了类似的东西:
file:///Users/rajeevrajani/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1339BAA2-127D-4C0C-8C35-5ADA33C46A70/DemoApp.app/0Dosing.html
我想将它加载到 UIWebview 中。
该怎么做?
【问题讨论】:
标签:
html
ios
core-data
uiwebview
nsurl
【解决方案1】:
在发布问题之前进行研究。
NSString *htmlFile = //ur file path put here...
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
它可能对你有帮助,谢谢。
【解决方案2】:
NSString *urlString = @"//filepath.html"; // get your file path here
NSURL *webPageURL = [NSURL URLWithString: urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:webPageURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0];
[_webView loadRequest:request]; // _webView is the UIWebView Outlet