[英]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.