1、UIWebView
UIWebView 是 苹果提供的用来展示网页的UI控件。它也是最占内存的控件。

iOS8.0 webkit框架。 WKWebView,相比UIWebView,节省了1/3~1/4的内存,速度快,但是没缓存功能。

 

iOS开发 Xcode native原生开发 + Html5 -> 混合开发

Android开发 Eclipse / MyEclipse Android Studio

Html5 javaScript css + div jquery + mobile DreamWare Sublime

 

iOS 和 HTML5

 

oc js 之间的交互

 

oc 调用 js 代码 stringByEvaluatingJavaScriptFromString

 

js 调用 oc 代码 苹果没提供,是通过代理来完成的。



//后退
[self.webView goBack];

//前进
[self.webView goForward];

//刷新
[self.webView reload];

//webView加载本地网页1

NSURL * htmlURL = [[NSBundle mainBundle] URLForResource:@"index.html" withExtension:nil];

[self.webView loadRequest:[NSURLRequest requestWithURL:htmlURL]];
//webview加载网络请求
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];

//webView加载本地网页2
NSString * path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString * htmlString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];

[self.webView loadHTMLString:htmlString baseURL:nil];

//如果网页不是响应式布局,需要调这个方法
self.webView.scalesPageToFit = YES;

//是否响应电话等信息
self.webView.dataDetectorTypes = UIDataDetectorTypeNone;

4、UIWebView 代理方法
/**
* 当用户点击网页某个连接,或者是按钮的时候出发
*
* @param webView
* @param request 网页上的连接请求
* @param navigationType
*
* @return 是否跳转到该连接
*/
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

NSLog(@"%@",request.URL);

return YES;
}

//网页开始加载
- (void)webViewDidStartLoad:(UIWebView *)webView {
self.backBtn.enabled = webView.canGoBack;
self.forwardBtn.enabled = webView.canGoForward;
}

//网页结束加载
- (void)webViewDidFinishLoad:(UIWebView *)webView {

self.backBtn.enabled = webView.canGoBack;
self.forwardBtn.enabled = webView.canGoForward;

//使用JavaScript进行编译
self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title”];

[self.webView stringByEvaluatingJavaScriptFromString:@"alert('登录成功')"];

}

//网页加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error {

NSLog(@"%@",error);
}