NSInvalidArgumentException – App terminates while i'm trying to copy a captured video to documents folder
I'd like to try the wisdom of the crowds..because i'm frustrated right now. Thanks in advance.
So here is my code:
- (void)imagePickerController:(UIImagePickerController *)ipc didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"info: %@",info);
NSString *newFilename = [NSString stringWithFormat:@"%@/%@.mov", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]]];
N开发者_运维知识库SLog(@"newFilename: %@",newFilename);
NSFileManager *filemgr = [NSFileManager defaultManager];
NSError *err; if ([filemgr copyItemAtPath:[info objectForKey:@"UIImagePickerControllerMediaURL"] toPath:newFilename error:&err] == YES) NSLog (@"Move successful"); else NSLog (@"Move failed");
and this is the log:
2010-05-16 18:19:01.975 erlkoenig[7099:307] info: {
UIImagePickerControllerMediaType = "public.movie";
UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/BE25F9B5-2D08-4B59-8B62-D04DF7BB7E5B/tmp/-Tmp-/capture-T0x108cb0.tmp.8M81HU/capturedvideo.MOV";
}
newFilename: /var/mobile/Applications/BE25F9B5-2D08-4B59-8B62-D04DF7BB7E5B/Documents/1274026741.mov
[NSURL fileSystemRepresentation]: unrecognized selector sent to instance 0x1c1f90
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL fileSystemRepresentation]: unrecognized selector sent to instance 0x1c1f90
I can follow you logic but have one fundamental issue: this is not how you save video.
Please see a rough example below without the relevant error checking.
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
.... code here .....
NSString* videoURL= [info objectForKey:UIImagePickerControllerMediaURL];
//remember to test that the video is compatible for saving to the photos album
UISaveVideoAtPathToSavedPhotosAlbum(videoURL, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
.... code here .....
}
精彩评论