1、将html文件夹拖入项目根目录下,选择引用(蓝色文件夹)
2、获取index.html所在的路径
3、webView调用loadFileURL:allowingReadAccessToURL:方法加载
如果需要拼接额外参数,需要手动拼接地址,直接用fileURLWithPath生成的链接,会进行编码
NSString *basePath = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] bundlePath], @"index.html所在的文件夹"];
NSURL *baseUrl = [NSURL fileURLWithPath: basePath isDirectory: YES];
NSString *filePath = [NSString stringWithFormat: @"file://%@/index.html#/?xxx=%@&sss=%@", basePath, @"xxx", @"sss"];
NSURL *fileUrl = [NSURL URLWithString: filePath];
[_webView loadFileURL: fileUrl allowingReadAccessToURL: baseUrl];