WKWebview没有加载本地HTML / CSSS文件

时间:2017-01-10 10:09:58

标签: ios ipad uiwebview wkwebview

我正在使用WKWebview加载本地html文件。该文件夹位于 tmp 目录中。 js和css的相对路径位于嵌套文件夹中。(../ css / font.css,.. / js / player.js),其中为父文件夹中的html。网址没有加载到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]]];   }

1 个答案:

答案 0 :(得分:0)

WKWebView仅从本地存储加载html。您可以使用local server作为加载文件。