[英]writeToFile gives NSUnderlyingError=0x6a3d450 “The operation couldn’t be completed. Is a directory”
I am trying to write file to a path in GCD but it doesn't work. 我正在尝试将文件写入GCD中的路径,但是它不起作用。 Keeps getting the error "NSUnderlyingError=0x6a3d450 "The operation couldn't be completed.
不断收到错误“ NSUnderlyingError = 0x6a3d450”,该操作无法完成。 Is a directory"
是目录”
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader", NO);
dispatch_async(downloadQueue, ^{
NSString* name = [photoDictionary valueForKey:@"title"];
path = [path stringByAppendingPathComponent:id];
if(![manager fileExistsAtPath:path]){
if([manager createDirectoryAtPath: path withIntermediateDirectories:NO attributes:nil error:nil]){ //create intermediate directories
data = [NSData dataWithContentsOfURL:[FlickrFetcher urlForPhoto:photoDictionary format:FlickrPhotoFormatOriginal]];
NSError *error = nil;
BOOL success = [data writeToFile:path options:NSDataWritingAtomic error:&error];
if (!success) {
NSLog(@"Failed to write to file with error: %@", [error description]);
}
if([data writeToFile: path atomically:YES]){
NSLog(@"data written to file");
}
}
}
else{
if([manager fileExistsAtPath:path]){
data = [manager contentsAtPath:path];
}
}
dispatch_async(dispatch_get_main_queue() , ^{
sender.navigationItem.rightBarButtonItem = item;
sender.photoData = data;
sender.photoName = name;
//call the segue
[sender performSegueWithIdentifier:segueTitle sender:sender];
});
});
dispatch_release(downloadQueue);
The problem that I am getting is that [data writeToFile: path atomically:YES] is never executed. 我遇到的问题是[data writeToFile:原子路径:是]从未执行。 However, the datapath was indeed created, and when I "po data" the program kinda hangs, so I guess the data was not fully fetched when the writeToFile is called.
但是,确实创建了数据路径,并且当我“ po data”该程序时有点挂起,因此我猜想在调用writeToFile时未完全获取数据。 However I cannot exactly pinpoint the problem and do not know how to solve it.
但是,我无法确切地指出问题,也不知道如何解决。 Any advices could be much appreciated.
任何建议,将不胜感激。 Thanks!
谢谢!
Your code is creating a directory at the path you're trying to next create the file at. 您的代码正在您要在其下创建文件的路径上创建目录。 Take that out or create the parent directory instead
取出来或创建父目录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.