UiWebView local HTML 离线情况加载

UiWebView local HTML loading in offline situation

I'm trying to load local HTML file in offline situation. I found a code here;


I'm using Reachability.h of Apple and it is working but I cant load local html file.

我以前用这个代码

加载本地 html

NSString *indexPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:nil]; [mWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];


https://gist.github.com/FatihDurmus/dba74b42425fe0f71685acec7be12aa8 这是我的控制器代码。

您可以使用此代码。有效。

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"terms_en" ofType:@"html"];
webView.delegate=self;
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

希望这对您有所帮助。 :)