【问题标题】:Loading local HTML file in UIWebView (the HTML file has css and jss files linked to it) iOS在 UIWebView 中加载本地 HTML 文件(HTML 文件有链接到它的 css 和 jss 文件)iOS
【发布时间】:2015-08-31 09:30:53
【问题描述】:

谁能告诉我为什么会出现这个错误以及如何解决这个错误。我正在尝试加载一个 html 文件,该文件本地保存在文档目录内的文件夹下。 html 文件具有链接到它的 jss 和 css 文件。请帮我解决这个问题。

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *path = [paths  objectAtIndex:0];

        NSLog(@"Saving");

        NSUserDefaults *prefs = [[NSUserDefaults alloc] init];

        bookid = [NSString stringWithFormat:@"%@",[prefs objectForKey:@"bookid"]];

        NSString *path1 = [NSString stringWithFormat:@"/%@",bookid];

        NSString *dataPath = [path stringByAppendingPathComponent:path1];

        dataPath = [dataPath stringByStandardizingPath];

        NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL];

        for (int count = 0; count < (int)[directoryContent count]; count++)
        {

                NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);

        }

        filePath = [dataPath stringByAppendingPathComponent:@"index.html"];

        NSString* htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
        [_BookReaderWeb loadHTMLString:htmlString
                        baseURL:[NSURL fileURLWithPath:dataPath]];

这是出现的错误:

Error Domain=NSURLErrorDomain Code=-1100 "在此服务器上找不到请求的 URL。" UserInfo=0x7ffb2a96acf0 {NSUnderlyingError=0x7ffb286b7d20“在此服务器上找不到请求的 URL。”,NSErrorFailingURLStringKey=file:///Users/ChanqBro/Library/Developer/CoreSimulator/Devices/A54D2148-91C3-49F4-B94C-CE46DEAEEC58/data /Containers/Data/Application/D08784A9-D5DD-41DE-95C5-DB97BE91BBBC/Library/Caches/3021/blank.html,NSErrorFailingURLKey=file:///Users/ChanqBro/Library/Developer/CoreSimulator/Devices/A54D2148-91C3- 49F4-B94C-CE46DEAEEC58/data/Containers/Data/Application/D08784A9-D5DD-41DE-95C5-DB97BE91BBBC/Library/Caches/3021/blank.html, NSLocalizedDescription=在此服务器上找不到请求的 URL。}

<html>
<head>
<meta charset="UTF-8">
<title> HELLO </title>

<!-- MONOCLE CORE -->
<script type="text/javascript" src="monocore.js"></script>
<script type="text/javascript" src="monoctrl.js"></script>  
<script type="text/javascript" src="book_data.js"></script>
<script type="text/javascript" src="test.js"></script>


<link rel="stylesheet" type="text/css" href="monocore.css" />
<link rel="stylesheet" type="text/css" href="monoctrl.css" />
<link rel="stylesheet" type="text/css" href="test.css" />

</head>
<body>
<div id="reader"></div>
</body>
</html>

【问题讨论】:

  • 各位有什么帮助吗??我被这个问题严重困扰! :(
  • 该目录下是否有名为blank.html的文件?
  • No jeffery 没有名为 blank.html 的文件。 html 在 safari 和 mozila 中打开,但在 Chrome 中没有打开,因为它有 iframe。
  • 为什么index.html 请求blank.html?在 HTML、CSS 或 JavaScript 中的某处,正在请求 URL。
  • 我将使用 html 文件编辑我的问题。请检查。

标签: ios objective-c iphone xcode uiwebview


【解决方案1】:

快速检查后,我发现您使用的是 Monocle。在搜索 monocle 和 blank.html 时,我发现 iOS 上 Monocle 的一些问题已通过将 HTML 文件添加到名为 blank.html 的空白页面来解决。

https://github.com/joseph/Monocle/issues/51https://github.com/joseph/Monocle/issues/99

所以现在将 blank.html 添加到你的根目录应该可以解决它。 (我自己不使用 UIWebView,所以我在这里继续你的建议!)

【讨论】:

  • 哇,非常感谢杰弗里!它对我有用 :) 太好了 :)
猜你喜欢
  • 2014-09-22
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
  • 2012-12-08
相关资源
最近更新 更多