直接上干货
允许网页加载本地资源
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
[config.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
_mWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Height) configuration:config];
加载沙盒html文件并传参
-(void)getFromLocalFile:(NSString *)custom_id{
NSString *documnet = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/"];
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/pano"];
NSString *tcPath = [path stringByAppendingPathComponent:@"/detail.html"];
if ([NSFileManager.defaultManager fileExistsAtPath:tcPath]) {
///加载沙盒html并传参
NSURL * url = [NSURL fileURLWithPath:tcPath isDirectory:NO];
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
//单一参数
[urlComponents setQuery:[NSString stringWithFormat:@"hall_id=%@",custom_id]];
//多参
// NSMutableArray *queryItemArray = [NSMutableArray array];
// [queryItemArray addObject:[NSURLQueryItem queryItemWithName:@"hall_id" value:@"5801"]];
// [urlComponents setQueryItems:queryItemArray];
[_mWebView loadFileURL:urlComponents.URL allowingReadAccessToURL:[NSURL fileURLWithPath: documnet]];
} else {
NSLog(@"没有文件");
}
}