同步方式:
1 解析本地HTML文件
{
NSString * htmlPath =[[NSBundle mainBundle] pathForResourse:@"index" ofType:@"html"];
NSURL *bundeleUrl =[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSError *error =nil;
NSString *html =[[NSString alloc] initWithContentsOfFlie:htmlPath encoding: NSUTF8StingEncoding error:&error];
if(error == nil){
[self.webView loadHTMLSting:html baseURL:bundleUrl];
}
}
2 提取本地数据
{
NSString * htmlPath =[[NSBundle mainBundle] pathForResourse:@"index" ofType:@"html"];
NSURL *bundeleUrl =[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSError *error =nil;
NSDate *htmlData =[[ NSData alloc ] initWithContentsOfFile:htmlPath];
if(error == nil){
[self.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL: bundleUrl ];
}
}
异步方式:
读取网络资源
{
NSURL *url =[NSURL URLWithString:@http://blog.csdn.net];
NSURLRequest *request =[NSURLReaquest requestWithURL :url];
[self,webView loadRequest :request];
self.webView.delegate =self;
}