【问题标题】:UIImagePickerControllerOriginalImage nil causing crash on photo captureUIImagePickerControllerOriginalImage nil 导致照片捕获崩溃
【发布时间】:2017-09-19 09:35:24
【问题描述】:

我的应用程序的多个版本都出现了崩溃,并且似乎已经开始在 iOS8 上发生。我只能通过崩溃报告来体验它,并且无法在我的测试设备上重现它。似乎是当用户捕获图像(或从库中选择它?)并且由于图像为零而无法设置原始图像。我在搜索时能找到的最接近的问题是:

https://github.com/B-Sides/ELCImagePickerController/issues/58

另一种可能性是当它以特定的比赛条件时间为背景时,我也无法重现。

http://openradar.appspot.com/19953748

但我不认为我的错误来自被选择的流图像。我希望看看是否有其他人收到此错误,并且已经找到了始终捕获异常的解决方案,或者检测何时发生这种情况,或者禁用特定的用户操作(例如在上传照片时将应用程序后台运行)以避免崩溃。

致命异常:NSInvalidArgumentException *** setObjectForKey: 对象不能为 nil (key: UIImagePickerControllerOriginalImage)

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2b381fef __exceptionPreprocess + 126
1  libobjc.A.dylib                0x39633c8b objc_exception_throw + 38
2  CoreFoundation                 0x2b29daa3 -[__NSDictionaryM setObject:forKey:] + 850
3  PhotoLibrary                   0x345bf8f3 __CreateInfoForImage
4  PhotoLibrary                   0x345bf1ad PLNotifyImagePickerOfImageAvailability
5  PhotoLibrary                   0x345d384b -[PLUICameraViewController cameraView:photoSaved:]
6  PhotoLibrary                   0x34606a73 -[PLImagePickerCameraView cropOverlay:didFinishSaving:]
7  PhotoLibrary                   0x3460706d -[PLImagePickerCameraView captureController:didCompleteResponse:forStillImageRequest:error:]
8  CameraKit                      0x303392a5 -[CAMCaptureController _completedResponse:forRequest:error:]
9  CameraKit                      0x30338bfb __56-[CAMCaptureController enqueueStillImageCaptureRequest:]_block_invoke_32160
10 libdispatch.dylib              0x39b9e2e3 _dispatch_call_block_and_release + 10
11 libdispatch.dylib              0x39b9e2cf _dispatch_client_callout + 22
12 libdispatch.dylib              0x39ba1d2f _dispatch_main_queue_callback_4CF + 1330
13 CoreFoundation                 0x2b347609 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
14 CoreFoundation                 0x2b345d09 __CFRunLoopRun + 1512
15 CoreFoundation                 0x2b292201 CFRunLoopRunSpecific + 476
16 CoreFoundation                 0x2b292013 CFRunLoopRunInMode + 106
17 GraphicsServices               0x32b71201 GSEventRunModal + 136
18 UIKit                          0x2ea36a59 UIApplicationMain + 1440
19 Pact                           0x000b26ab main (main.m:17)
20 libdyld.dylib                  0x39bbfaaf start + 2

编辑 2017 年 9 月 18 日我没有重新审视这个问题,也没有找到解决方案,不幸的是:(

【问题讨论】:

  • “我在搜索时能找到的最接近的问题是这个”。我做了一个谷歌搜索,没有任何相关的东西出现。因此,发布有关堆栈溢出的问题。希望谷歌搜索会导致这个问题。
  • 好的,我会用谷歌搜索它你。例如,我发现了这个:openradar.appspot.com/19953748 我认为很有见地。
  • 感谢您的链接。我记得看过那个。看起来他们也没有任何回应或解决方案。所以,要跟进,也许我的问题需要重新措辞 - 有没有人对此有解决方案?即使在后台运行时,我也无法在我的应用中重现崩溃。
  • "有人有解决方案吗" 是的,这可能是一个更好的问题。但不要期待答案。我认为所有迹象都表明这是苹果公司的一个错误。 (您一定已经注意到 UIImagePickerController 在其他方面也存在问题。)
  • 嗨@mitrenegade 提出问题的完全合理的地方,事实上,谷歌搜索现在确实引导到这里,我得到有用的答案,这是我可以雷达和忽略的东西。我不太确定为什么上面 cmets 中的“某些人”似乎会考虑您,我和其他人从堆栈溢出中发现这是“一件让他们脾气暴躁的坏事,他们需要我们知道这一点”。也许我们可以从这种态度中推断出关于那些人的事情。谁知道呢。

标签: ios


【解决方案1】:

我能够从基于 http://openradar.appspot.com/19953748 的场景中重现此崩溃。我设置了一个无限循环,每 2 秒拍一张照片,我不断地在背景和前景之间移动应用程序。它很快就因相同的堆栈跟踪而崩溃。虽然我不确定其根本原因,但我可以通过在拍照前检查应用程序状态来解决它

//Swift
if UIApplication.sharedApplication().applicationState == .Active {
                // Take picture
} 

【讨论】:

  • 我发现如果 flashMode 设置为 On,我几乎可以 100% 地复制这个。只需按下快门按钮,然后快速按下电源按钮即可锁定手机。如果您遇到这种情况,请通过 bugreport.apple.com 提交 Radar。这是我的:openradar.appspot.com/28108858
  • @Kedar 嗨,我刚刚发现了同样的问题。你到底把你的代码放在哪里了?我仍然得到崩溃。我试过了: func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { if UIApplication.shared.applicationState == .active { if let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {..}
【解决方案2】:
  If you write tap gesture or action sheet,just check the below code with your code. 

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  {
     UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];
     pickerController.delegate=self;
     if(buttonIndex==0)
     {
         pickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
         [self presentViewController:pickerController animated:YES completion:nil];
     }
     else if(buttonIndex==1)
     {
         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES)
        {
            NSLog(@"Camera is available and ready");
            pickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:pickerController animated:YES completion:nil];
        }
        else
        {
            NSLog(@"Camera is not available");
            [[[UIAlertView alloc]initWithTitle:@"Whoa !" message:@"Camera is not available" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]show];
        }
    }

  }

然后在委托方法中,

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

       UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
       imageView.image = image;
       [picker dismissViewControllerAnimated:YES completion:nil];
   }

【讨论】:

  • 在使用图像填充信息时似乎发生了异常;在堆栈跟踪中,发生崩溃是因为相机框架试图将键 UIImagePickerControllerOriginalImage 的值设置为 nil。我试图理解为什么我们选择的图像可能是 nil - 它认为这不是内存问题,因为所有崩溃报告都没有显示内存警告。
  • @mitrenegade 你找到它的原因和解决办法了吗?
  • 我还没有重温这个。我记得的最后一件事是它可能与加载云照片有关。不幸的是,尽管马特的帮助没有回答(/s)
  • 我上面的编码对你有帮助吗?
  • @mitrenegade 有没有解决这个崩溃问题的方法,我也面临 nil 问题,请指教
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-02
相关资源
最近更新 更多