这是我试过的 –
Nsstring *stringURL = @"url to file";NSURL *url = [NSURL URLWithString:stringURL];NSData *urlData = [NSData dataWithContentsOfURL:url];if ( urlData ){ NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES); Nsstring *documentsDirectory = [paths objectAtIndex:0]; Nsstring *filePath = [Nsstring stringWithFormat:@"%@/%@",documentsDirectory,@"index.HTML"]; [urlData writetofile:filePath atomically:YES];} //Load the request in the UIWebVIEw. [web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"HTML"]isDirectory:NO]]]; // Do any additional setup after loading the vIEw from its nib.
但这会给出“SIGABRT”错误。
不太确定我做错了什么?
任何帮助将不胜感激。谢谢!
解决方法 传递给UIWebVIEw的路径是不正确的,就像Freerunnering所提到的,尝试改为:// Determile cache file pathNSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES);Nsstring *filePath = [Nsstring stringWithFormat:@"%@/%@",[paths objectAtIndex:0],@"index.HTML"]; // Download and write to fileNSURL *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]]];
注意:需要添加正确的错误处理。
总结以上是内存溢出为你收集整理的iphone – iOS下载并保存HTML文件全部内容,希望文章能够帮你解决iphone – iOS下载并保存HTML文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)