我想使用ASIWebPageRequest加载本地html文件,以便我可以使用ASIWebPageRequest中的内置缓存。我知道这可能听起来有点毫无意义,但是我想在本地文件中使用远程图像,每周只更新一次。如果这是有道理的。ASIHTTPRequest和ASIWebPageRequest加载本地HTML文件错误
下面是我在做什么代码:
//OUTPUT: file:///Users/ledixonuk/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/FDF21331-CC80-4ECB-9A33-16AEC073D117/Documents/ItemOne.html
NSURL *fileUrl = [[NSURL alloc] initFileURLWithPath:[FileSystemHelper dataFilePathInDocuments:@"ItemOne.html"]];
// Assume request is a property of our controller
// First, we'll cancel any in-progress page load
[[self webRequest] setDelegate:nil];
[[self webRequest] cancel];
[self setWebRequest:[ASIWebPageRequest requestWithURL:fileUrl]];
[[self webRequest] setDelegate:self];
[[self webRequest] setDidFailSelector:@selector(webPageFailed:)];
[[self webRequest] setDidFinishSelector:@selector(webPageFinished:)];
// Tell the request to replace urls in this page with local urls
//[[self webRequest] setUrlReplacementMode:ASIReplaceExternalResourcesWithLocalURLs];
// Tell the request to embed external resources directly in the page
[[self webRequest] setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
// It is strongly recommended you use a download cache with ASIWebPageRequest
// When using a cache, external resources are automatically stored in the cache
// and can be pulled from the cache on subsequent page loads
[[self webRequest] setDownloadCache:[ASIDownloadCache sharedCache]];
// Ask the download cache for a place to store the cached data
// This is the most efficient way for an ASIWebPageRequest to store a web page
[[self webRequest] setDownloadDestinationPath:[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:[self webRequest]]];
[[self webRequest] startAsynchronous];
,这里是错误我得到:
404未找到
未找到
请求的URL /用户/ ledixonuk /库/应用程序支持/ iPhone模拟器/ 4.3.2/Ap在此服务器上找不到FDF21331-CC80-4ECB-9A33-16AEC073D117/Documents/ItemOne.html。
显然ASIWebPageRequest无法找到应用程序文件夹中的文件ItemOne.html但是我仔细检查过,文件肯定是有。
有没有其他人有类似的问题呢?这让我疯狂地试图把它解决掉!
我测试过这个,它有同样的问题,谢谢。 – AggroPanda 2011-06-14 08:35:27