iOS WKWebView 使用笔记
首先添加Webkit框架
导入#import <WebKit/WebKit.h>
#import <WebKit/WebKit.h> @interface WebBrowerViewController ()<WKNavigationDelegate> @property(nonatomic,strong) WKWebView *webView; @end @implementation WebBrowerViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view addSubview:self.webView]; [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]]; } -(WKWebView *)webView { if (!_webView) { _webView = [[WKWebView alloc] initWithFrame:self.view.bounds]; _webView.navigationDelegate = self; } return _webView; } //1.1.1 页面开始加载时调用 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { NSLog(@"页面开始加载..."); } //1.1.2 当内容开始返回时调用 - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation { NSLog(@"内容开始返回..."); } //1.1.3 页面加载完成之后调用 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { NSLog(@"页面加载完成..."); } //1.1.4 页面加载失败时调用 -(void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { NSLog(@"页面加载失败..."); } @end
作者:SIBU iOS DEV
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.