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

 

posted @ 2015-08-25 10:16  sixindev  阅读(679)  评论(0编辑  收藏  举报