This is how to load/use a local html with relative references.
- Drag the resource into your xcode project (I dragged a folder named www from my finder window), you will get two options “create groups for any added folders” and “create folders references for any added folders”.
- Select the “create folder references..” option.
-
Use the below given code. It should work like a charm.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
Now all your relative links(like img/.gif, js/.js) in the html should get resolved.
Swift 3
if let path = Bundle.main.path(forResource: "dados", ofType: "html", inDirectory: "root") {
webView.load( URLRequest(url: URL(fileURLWithPath: path)) )
}