【问题标题】:WKWebview not loading local HTML/CSS fileWKWebview 不加载本地 HTML/CSS 文件
【发布时间】:2017-05-24 18:58:39
【问题描述】:

我正在使用 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]]];   }

【问题讨论】:

  • 如果打印出 urlToLoad 字符串怎么办?
  • 您能否在问题正文中通过编辑来澄清您的问题?

标签: ios ipad uiwebview wkwebview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-12-26
    • 2018-01-29
    • 2016-04-08
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 2014-09-13
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多