简体   繁体   English

为UIImagePickerController选择视频时崩溃

[英]Crash When Selecting Video For UIImagePickerController

I have a UIImagePicker that is being used to pull in videos on my new application. 我有一个UIImagePicker,用于在我的新应用程序上提取视频。 I have noticed that according to Crashlytics I am receiving a number of crashes where the below movieURL is nil when inserting into the movie array. 我注意到根据Crashlytics我收到了一些崩溃,其中插入电影数组时下面的movieURL为零。

I tested it before release with a number of videos and all seems to be fine. 我在发布之前用一些视频测试了它,一切似乎没问题。 As mentioned however since release I have had a number of crashes. 如上所述,自发布以来,我遇到了许多崩溃事件。

The error report in question is: 有问题的错误报告是:

Exception: NSInvalidArgumentException 
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

The actual code the receives the video is as follows: 接收视频的实际代码如下:

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

    NSURL *movieURL = [info valueForKey:@"UIImagePickerControllerMediaURL"];

    CompileViewController *compileViewController = [[CompileViewController alloc] init];
    compileViewController.movieArray = [[NSMutableArray alloc] init];
    [compileViewController.movieArray insertObject:movieURL atIndex:0];

     [picker dismissViewControllerAnimated:NO completion:nil];

    [self.navigationController pushViewController:compileViewController animated:NO];


}

Here is the code for selecting the video with the picker. 以下是使用选择器选择视频的代码。

-(IBAction)loadVideo {

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    //imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes =  [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
    [self presentViewController:imagePicker animated:NO completion:nil];

} }

I was wondering what could be causing the user to provide a nil result for "UIImagePickerControllerMediaURL" and how I could go about resolving this issue. 我想知道是什么原因可能导致用户为“UIImagePickerControllerMediaURL”提供nil结果以及我如何解决这个问题。 I have looked at trying to capture an error but I don't think the method has one. 我已经看过尝试捕获错误,但我不认为该方法有一个。 I think I could check for the nil value before entering it into the array but I would like to know why the result is coming back as nil in the first place. 我想我可以在进入数组之前检查nil值,但我想知道为什么结果首先回到nil。

Thanks 谢谢

Are you properly limiting the media selection choices for your UIImagePickerController? 您是否正确限制UIImagePickerController的媒体选择选项? It is possible, depending on configuration, to not get what you are expecting. 根据配置,可能无法获得您期望的结果。

Your code is assuming that the value you are retrieving from the dictionary will exist and be valid. 您的代码假定您从字典中检索的值将存在且有效。 Your runtime crashes are telling you that's not true. 你的运行时崩溃告诉你这不是真的。

Could you post the setup code where you configure your UIImagePickerController? 您可以在配置UIImagePickerController的地方发布设置代码吗? In particular, have you done things like verify availability (using isSourceTypeAvailable: and availableMediaTypesForSourceType:), etc? 特别是,您是否已经完成了验证可用性(使用isSourceTypeAvailable:和availableMediaTypesForSourceType :)等操作?

If you're leaving open any possible path for user to get out of you UIImagePickerController without recording a movie, there will be no file and hence no URL pointing to it (url will be nil). 如果你打开任何可能的路径让用户离开UIImagePickerController而不录制电影,那么就没有文件,因此没有指向它的URL(url将为nil)。

Edit -- 编辑 -

Based on your comments, I don't see any obvious problems. 根据您的意见,我没有看到任何明显的问题。 But there may be issues with configuration, movie format and/or user-granted permissions for access. 但是配置,电影格式和/或用户授予的访问权限可能存在问题。 I'd act on these two warnings from documentation: 我会根据文档对这两个警告采取行动:

Always call the isSourceTypeAvailable: class method of the UIImagePickerController class and respect its return value. 始终调用UIImagePickerController类的isSourceTypeAvailable:class方法并尊重其返回值。 Never assume that a device has a photo library. 永远不要假设设备有照片库。 Even if the device has a library, this method could still return NO if the library is currently unavailable. 即使设备有库,如果库当前不可用,此方法仍可返回NO。

and

[media type]: However, before setting this property, check which media types are available by calling the availableMediaTypesForSourceType: class method. [media type]:但是,在设置此属性之前,请通过调用availableMediaTypesForSourceType:class方法检查哪些媒体类型可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM