tags:

views:

17

answers:

1

I am calling –writeToFile:atomically: on an NSData object which contains a video I just shot. The file is not being written and if I use the version that returns an erorr object, the error is nil.

My code is:

if ([[info valueForKey:UIImagePickerControllerMediaType] isEqualToString:@"public.movie"]) {
        NSURL* url = [info valueForKey:UIImagePickerControllerMediaURL];
        NSData *videoData = [NSData dataWithContentsOfURL:url];
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *fPath = [documentsDirectory stringByAppendingPathComponent:@"capturedVideo.MOV"];
        [videoData writeToFile:fPath atomically:YES];
}

The return value is NO and when I check the existence of the written file, it is not there.

Any ideas?

A: 

Try creating file with NSFileManager before writing to it.

eviltrue
Just tried that and I have the same problem. BUT even before I tried that, I noticed another clue. I am actually getting a YES from writeToFile and if I check if the file exists right after I write it, I get a YES. But then when I check if it exists later on (in the same session), I get a NO. I printed out the two paths and they are identical. So writeToFile must create the file itself. Am I missing something? (obviously since it doesn't work yet)
Jack Widman
I don't how this can help, but however, on emulator you can make sure that file is created and find the moment it disappears with finder.
eviltrue