需要注意的是, baseURL 可以用来控制请求权限
2.加载本地文件
- (void)loadHTMLContent {
//加载本地文件
NSString *rootPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSURL *rootURL = [NSURL fileURLWithPath:rootPath];
NSString *bodyTargetPath = [rootPath stringByAppendingPathComponent:@"index.html"];
NSURL *url = [NSURL fileURLWithPath:bodyTargetPath];
//这里必须指定到沙盒的具体文件夹,不能再沙盒根目录上
[webview loadFileURL:url allowingReadAccessToURL:rootURL];
}
重定向请求
1.通过 URLProtocol
新建 Protocol 的子类,并添加请求属性
@property (nonnull,strong) NSURLSessionDataTask *task;
由于 WKWebview 的特殊性,这里需要新建类别,并注册需要监听的请求头 [NSURLProtocol wk_registerScheme:@"http"];
注册监听 [NSURLProtocol registerClass:[BZURLProtocol class]];
过滤需要进行处理的请求,同时也要过滤那些已经处理过的请求。










