Captured Video on iPhone, trying to move it to another directory
Using UIImagePickerController
, I have captured a video. When I call [picker stopVideoCapture]
, then the following delegate method is called:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSLog(@"attempting to copy: %@ to: %@", [url absoluteString], [NSString stringWithFormat:@"%@/rawMovie.MOV",path]);
if ([fileManager moveItemAtPath:[url absoluteString] toPath:[NSString stringWithFormat:@"%@/rawMovie.MOV",path] error:&error] != YES)
NSLog(@"Can't move file with error: %@", [error localizedDescription]);
}
When this method is called however, it returns an error reading:
The operation couldn’t be completed. (Cocoa error 4.)
As far as I have been able to tell, this means that the file cannot be copied for some unknown reason. Can anyone give me a better answer as to why this error is being thrown? Or, better yet, can anyone tell me the best way to save the captured video di开发者_运维知识库rectly to the app's documents directory?
Thanks, James
Why dont you put breakpoints & see the output of *path
and url
. Also do you have enough disk space to store your video on the device?
I think you need to use the default file manager:
NSFileManager* fileManager = [NSFileManager defaultManager];
You can also log the error's userinfo for (hopefully) more details.
NSLog(@"Can't move file with error: %@", [error userInfo]);
精彩评论