【发布时间】:2014-12-20 01:25:31
【问题描述】:
我正在开发一个应用程序,我必须下载一个完整的目录。该目录将包含例如:
article1/index.html
/images/image1.png
/image2.png
/image3.png...
我试过下载这个,但我只能下载 index.html。
我正在使用此代码:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Downloading Started");
NSString *urlToDownload = @"http://localhost:8888/";
NSURL *url = [NSURL URLWithString:urlToDownload];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/issue/article%@/", documentsDirectory,articleID];
NSLog(@"filepath: %@", filePath);
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:filePath atomically:NO];
NSLog(@"File Saved !");
});
}
});
如果有人有想法。告诉我。
谢谢
【问题讨论】:
标签: ios objective-c grand-central-dispatch nsdata nsdocumentdirectory