ios - UIImagePickerController 在 alloc/init 上崩溃

标签 ios ipad uiimagepickercontroller

我有一个 UIImagePickerController,当用户按下按钮时,它会显示在弹出窗口中。这在 iPad 模拟器中完全正常,但当我尝试在实际测试设备上执行相同的操作时,我在图像选择器的 alloc/init 行上收到 NSRangeException!

    imagePicker = [[UIImagePickerController alloc] init];//Crashes here on device
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil];

这是崩溃消息:

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSOrderedSet initWithOrderedSet:range:copyItems:]: range {8, 1} extends beyond bounds [0 .. 0]'

我通过尝试在 Debug模式下跨过该行来确定这正是该行,并且跨过该特定行是导致抛出异常的原因。

编辑:

我能够制作一个 100% 重现此问题的基本项目,这让我相信这是一个 iOS 错误,而不是我的代码的问题。

  1. 创建一个新项目。选择单一 View 应用程序。无论是 Storyboard还是基于 xib 都没有关系
  2. 打开 iPad xib/storyboard,向 View 添加一个圆形按钮
  3. 将以下 IBAction 添加到 View Controller 。 pickerPopoverController 是一个 __strong ivar

    -(void)iMakeItCrash:(UIButton*)sender
    {
        UIImagePickerController* ip = [[UIImagePickerController alloc] init];
        ip.delegate = self;
        ip.allowsEditing = YES;
        ip.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        ip.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil];
    
        pickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:ip];
        [pickerPopoverController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    
  4. 将此 IBAction 关联到按钮的 Touch Up Inside 事件。

  5. 在模拟器上运行,在 iPad 上崩溃

编辑2:

如果我尝试使用 presentPopoverFromBarButtonItem:,仍然会发生崩溃。但是,如果我根本不显示图像选择器,则不会崩溃...

最佳答案

当我的应用程序在我的任何设备或模拟器上的空“已保存照片”相册中崩溃时,我注意到了这一点。如果“保存的照片”中有照片,则不会发生该错误。如果您在模拟器上使用“重置数据和设置”并将相册留空,则很容易复制。

我花了很长时间试图找到解决方法,但一直没能找到。我认为提交 iOS 错误报告是一个真正的好主意。

关于ios - UIImagePickerController 在 alloc/init 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10702979/

相关文章:

ios - UIImagePickerController 作为应用程序的主视图 Controller 和随后显示的导航 Controller

ios - 如何在iOS应用程序中将小数位限制为四位

ios - NSFetchRequest 没有看到 NSManagedObjectContext 中关系的变化

javascript - iPad JavaScript 计时器停止运行检测到 sleep 模式

ios - 分配 cameraOverlyView 属性时未调用 UIImagePickerController didFinishPickingMediaWithInfo

ios - Swift 3 上传视频到服务器

ios - 可本地化的字符串!!!! bundle (路径)尚未加载

ios - viewDidDisappear 后键盘不会消失

objective-c - 如何正确使用 CCSpriteFrameCache 和 CCSpriteBatchNode?

ios - 用于编辑和非编辑文本字段的不同弹出窗口