简体   繁体   English

writeToFile给NSUnderlyingError = 0x6a3d450“该操作无法完成。 是目录”

[英]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.

相关问题 使用writeToFile无法完成该操作 - The operation couldn’t be completed with writeToFile 该操作无法完成。 没有这样的文件或目录:但是文件存在 - The operation couldn’t be completed. No such file or directory: but the file exists 该操作无法完成。 可可错误4 - The operation couldn’t be completed. Cocoa Error 4 XCode 4 存档/IPA 错误:“操作无法完成。 没有这样的文件或目录” - XCode 4 Archive/IPA Error: “The operation couldn’t be completed. No such file or directory” NSStream-操作无法完成。 拒绝连接 - NSStream - The operation couldn’t be completed. Connection refused 该操作无法完成。 (可可错误1560.) - The operation couldn’t be completed. (Cocoa error 1560.) MidiClientCreate“操作无法完成。 (OSStatus错误-50。)” - MidiClientCreate “The operation couldn't be completed. (OSStatus error -50.)” 该操作无法完成。 (可可错误:3840。) - The Operation couldn't be completed. (Cocoa error: 3840.) “这项行动无法完成。 (可可错误512.)“ - “The operation couldn’t be completed. (Cocoa error 512.)” ITLibrary:无法完成操作。 (OSStatus 错误 7011。) - ITLibrary: The operation couldn’t be completed. (OSStatus error 7011.)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM