iOS下载整个HTML页面并在webView上从本地进行展示



多亏了法律,我解决了设备中的显示问题。但我仍然需要解决图像问题。必须连同HTML和展览一起下载它们,有什么提示吗?

编辑:

-固定实际上我使用的是这个代码,我在另一个线程中从Anne那里得到的。它在iOS模拟器上工作(不显示图像,也不显示html以外的任何内容),但当我尝试在设备中运行时,它没有显示任何内容(甚至没有控制台错误),这是怎么回事?

// Determile cache file path
NSString *path = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", path, @"index.html"];   
// Download and write to file
NSURL *url = [NSURL URLWithString:@"http://www.google.nl"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
// Load file in UIWebView
[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];      

修复了到的路径

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

这是因为你不能在设备上写入捆绑包,尽管它在模拟器上可以工作。

请参阅技术问答;直接从Apple 获取更多详细信息的QA1662

最新更新