【发布时间】:2015-08-14 14:07:24
【问题描述】:
我想将缓存数据复制到数据库(sqlite/coreData)中,以便我可以在离线(没有互联网)时查看,如“Safari 中的阅读列表”。我在Xcode UIWEBVIEW download , save HTML file and show阅读了代码 以下是:-
- (void)viewDidLoad
{
NSURL *url = [NSURL URLWithString:@"http://livedemo00.template-help.com/wt_37587/index.html"];
//[WEBVIEW loadRequest:reqURL];
// Determile cache file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
// Download and write to file
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
// Load file in UIWebView
[WEBVIEW loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
[super viewDidLoad];
}
但是这段代码的问题是它在离线时不显示图像。
所以我认为将数据从缓存保存到数据库可能是另一种选择。任何人都可以分享一些示例代码来将网站内容与图像一起复制到数据库。
提前谢谢你
【问题讨论】:
标签: ios objective-c caching uiwebview