標籤:
首先添加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
iOS WKWebView 使用筆記