简体   繁体   English

UIImagePickerControllerOriginalImage nil导致照片捕获崩溃

[英]UIImagePickerControllerOriginalImage nil causing crash on photo capture

I am getting a crash in several versions of my apps, and it seems to have started happening on iOS8. 我的应用程序的几个版本崩溃了,似乎已经开始在iOS8上发生了。 I only experience it through crash reports and can't reproduce it on my test devices. 我只通过崩溃报告来体验它,并且无法在我的测试设备上重现它。 It seems to be when a user captures an image (or selects it from the library?) and the original image cannot be set because the image is nil. 似乎是当用户捕获图像(或从库中选择它?)时,由于图像为零,因此无法设置原始图像。 The closest issue I can find while searching is this: 我在搜索时可以找到的最接近的问题是:

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

Another possibility is when it is backgrounded with a specific race condition timing, which I'm also unable to reproduce. 另一种可能性是当它以特定的竞争状态时序为背景时,我也无法重现。

http://openradar.appspot.com/19953748 http://openradar.appspot.com/19953748

but I don't think my error is coming from a stream image being selected. 但我认为我的错误不是来自正在选择的流图像。 I'm hoping to see if anyone else is getting this error, and has either figured out a solution to consistently catch the exception, or detect when this happens, or disable a specific user action (like backgrounding the app while uploading photos) to avoid a crash. 我希望看看是否有其他人收到此错误,并且已找出一个解决方案以始终捕获异常,或检测何时发生这种情况,或禁用特定的用户操作(如在上传照片时设置应用程序)以避免崩溃。

Fatal Exception: NSInvalidArgumentException *** setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage) 致命异常:NSInvalidArgumentException *** setObjectForKey:object不能为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

EDIT Sept 18, 2017 I have not revisited this issue and have not found a solution, unfortunately :( 编辑2017年9月18日我没有重新审视这个问题,并且没有找到解决方案,不幸的是:(

I was able to reproduce this crash from exactly the scenario based in http://openradar.appspot.com/19953748 . 我能够完全根据http://openradar.appspot.com/19953748中的场景重现此崩溃。 I set up an infinite loop that took a picture every 2 seconds and I continuously moved the app between background and foreground. 我设置了一个无限循环,每2秒拍一张照片,我不断在背景和前景之间移动应用程序。 It crashes with the same stack trace pretty quickly. 它很快就崩溃了相同的堆栈跟踪。 Though I am not sure of the root cause for this I am able to resolve it by simply checking for application state before taking the picture 虽然我不确定其根本原因,但我可以通过在拍照之前检查应用程序状态来解决它

//Swift
if UIApplication.sharedApplication().applicationState == .Active {
                // Take picture
} 
  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];
        }
    }

  }

Then in delegate method, 然后在委托方法中,

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

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

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

相关问题 InstantiateViewController导致nil导致崩溃 - InstantiateViewController resulting a nil causing it to crash Swift 4 Capture Photo,photoOutput返回nil - Swift 4 Capture Photo, photoOutput returns nil 地图视图:GMSMapView! nil 导致应用程序崩溃(迅速) - mapView: GMSMapView! nil causing the app to crash (swift) Swift 协议 - 委托为零,导致崩溃 - 不是关于 Optionals - Swift Protocols - Delegate Is Nil, Causing Crash - NOT About Optionals iOS 10 - 更改相机、麦克风和照片库的权限导致应用程序崩溃 - iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash UIImagePickerControllerMediaURL对于照片始终为零 - UIImagePickerControllerMediaURL always nil for a photo 使用捕获列表中的无主内容导致崩溃,甚至块本身也不会被执行 - Using unowned inside of a capture list causing a crash even the block itself isn't executed 使用叠加图片捕获照片 - Capture photo with overlay picture 在Swift中使用AVFoundation捕获照片 - Capture photo with AVFoundation in Swift 崩溃:commitEditingStyle -deleteObject为零 - Crash :commitEditingStyle -deleteObject is nil
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM