UIImagePickerControllerOriginalImage nil导致照片捕获崩溃

时间:2015-04-24 00:04:38

标签: ios

我的应用程序的多个版本出现崩溃,似乎已经开始在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日我没有重新审视这个问题,但遗憾的是没有找到解决方案:(

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

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