【发布时间】: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