iOS WKWebView 加载本地html

目录如图
屏幕快照 2018-10-17 下午5.19.45.png
导入 #import
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:wkWebView];
    
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *basePath = [NSString stringWithFormat:@"%@",bundlePath];
NSURL *baseUrl = [NSURL fileURLWithPath:basePath isDirectory:YES];
NSString *indexPath = [NSString stringWithFormat:@"%@/driverCode.html",basePath];
NSString *indexContent = [NSString stringWithContentsOfFile:indexPath encoding:NSUTF8StringEncoding error:NULL];
[wkWebView loadHTMLString:indexContent baseURL:baseUrl];

你可能感兴趣的:(iOS WKWebView 加载本地html)