0

I am using WKWebview to load local html file. the folder resides in tmp directory. The relative path of js and css are in nested folders.(../css/font.css,../js/player.js), where as html in parent folder. The Url not loading in the wkwebview

Root folder name - HTMLFiles
Root HTML Path -  HTMLFiles/HTML/index.html
CSS path - HTMLFiles/design/CSS/font.css
JS path - HTMLFiles/JSPath/JS/player.js

> > Below I am trying to read from temp directory and loading into
>     > wkwebview urlToLoad =  [NSString
>     > stringWithFormat:@"file://%@/HTMLFiles/HTML/index.html",
>     > NSTemporaryDirectory()];; SEL sel =
>     > NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:"); if
>     > ([self.webView respondsToSelector:sel] &&
>     > self.useLoadFileURLreadAccessURL) {    NSString* directory =
>     > [self.urlToLoad stringByDeletingLastPathComponent];
>     >         ((id (*)(id, SEL, id, id))objc_msgSend)(self.webView, sel, [NSURL URLWithString:self.urlToLoad], [NSURL
>     > URLWithString:directory]);
>     >         [_webView loadFileURL:[NSURL URLWithString:self.urlToLoad] allowingReadAccessToURL:[NSURL
> URLWithString:directory]];
>     >     } else {
>     >         // load the passed in URL
>     >         [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlToLoad]]];   }
2
  • What if, when you print out the urlToLoad String? Commented Jan 10, 2017 at 10:29
  • Could you clarify your problem in the body of your question, by editing it? Commented Jan 10, 2017 at 11:09

1 Answer 1

0

WKWebView load only html from local storage. You can use local server for load files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.