NSInvalidArgumentException - the application terminates when I try to copy the captured video to the document folder

I would like to try the wisdom of the crowd ... because now I'm upset. 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 ]]];

NSLog (@ "newFilename:% @", newFilename);

NSFileManager * filemgr = [NSFileManager defaultManager];

NSError * err; if ([filemgr copyItemAtPath: [info objectForKey: @ "UIImagePickerControllerMediaURL"] toPath: newFilename error: & err] == YES) NSLog (@ "Move successfully"); another 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
+3
source share
1 answer

I can follow the logic, but it has one fundamental problem: this is not how you save the video .

Please see the example below without proper 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 .....

}
0
source

Source: https://habr.com/ru/post/1745660/


All Articles