NSInvalidArgumentException – 当我尝试将捕获的视频复制到文档文件夹时应用程序终止

发布于 2024-09-01 16:56:40 字数 1458 浏览 1 评论 0原文

我想尝试一下群众的智慧……因为我现在很沮丧。 提前致谢。

所以这是我的代码:

- (void)imagePickerController:(UIImagePickerController *)ipc didFinishPickingMediaWithInfo:(NSDictionary *)info{

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

NSString *newFilename = [NSString stringWithFormat:@"%@/%@.mov", [NSHomeDirectory() stringByAppendingPathComponent:@"文档"], [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]]];

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

NSFileManager *filemgr = [NSFileManager defaultManager];

NSError *错误; if ([filemgr copyItemAtPath:[info objectForKey:@"UIImagePickerControllerMediaURL"] toPath:newFilename 错误:&err] == YES) NSLog(@"移动成功"); 别的 NSLog(@"移动失败");

这是日志:

 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'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]]];

NSLog(@"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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朱染 2024-09-08 16:56:40

我可以遵循您的逻辑,但有一个基本问题:这不是保存视频的方式

请看下面的一个粗略示例,没有进行相关的错误检查。

(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 .....

}

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 .....

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文