UIWEBVIEW和WKWebView学习

96
锦鲤跃龙
2017.04.21 10:19* 字数 10

UIWebViewDelegate

UIWebViewNavigationType{
UIWebViewNavigationTypeLinkClicked,点击链接
UIWebViewNavigationTypeFormSubmitted,提交表单
UIWebViewNavigationTypeBackForward,点击前进或返回按钮
UIWebViewNavigationTypeReload,点击重新加载按钮
UIWebViewNavigationTypeFormResubmitted,重复提交表单
UIWebViewNavigationTypeOther,发生其它行为
}
  __TVOS_PROHIBITED @protocol UIWebViewDelegate <NSObject>
    @optional
//询问是否允许加载页面请求。UIWebViewNavigationType是个枚举。 可以通过判断不同的枚举值拿到事件,进行操作。
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
//页面开始加载
    - (void)webViewDidStartLoad:(UIWebView *)webView;
//页面加载完成
    - (void)webViewDidFinishLoad:(UIWebView *)webView;
//页面加载失败
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error;

    @en

WKWebView的WKNavigationDelegate比uiwebViewdelegate更加细化

@protocol WKNavigationDelegate <NSObject>

@optional
//请求之前,决定是否要跳转:用户点击网页上的链接,需要打开新页面时,将先调用这个方法。
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;
//接收到相应数据后,决定是否跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler;
//页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation;
// 主机地址被重定向时调用
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation;
// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;
// 当内容开始返回时调用
- (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation;
// 页面加载完毕时调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation;
//跳转失败时调用
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;
// 如果需要证书验证,与使用AFN进行HTTPS证书验证是一样的
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *__nullable credential))completionHandler;
//9.0才能使用,web内容处理中断时会触发
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView NS_AVAILABLE(10_11, 9_0);

@end
日记本