setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)

The developed APP uses Youmeng to perform crash statistics. I recently saw the above problems, but I could not reproduce them. After searching, I found the following information:
http://stackoverflow.com/questions/29836488/uiimagepickercontrolleroriginalimage-nil-causing-crash- on-photo-capture
http://openradar.appspot.com/19953748

It can be inferred that the reason for this problem is that you lock the screen or return to the desktop while taking pictures .
But after I tried it, I still couldn't reproduce it.
Finally, I saw a key point in the following post: the flash:
https://openradar.appspot.com/28108858

So I turned on the flash before taking pictures, then took pictures and locked the screen at the same time.
At this time, you can see an error message in the Xcode console log:

* Camera: Error capturing still image (Error Domain=AVFoundationErrorDomain Code=-11800 "This operation could not be completed" UserInfo=0x170675d40 {NSUnderlyingError=0x17064a950 "The operation could not be completed. ("OSStatus" error -16800.)", NSLocalizedFailureReason=Happened Unknown error (-16800), NSLocalizedDescription=This operation cannot be completed})
2016-11-11 11:20:46.524 GDTaxService[1971:938033] * Camera: captureStillImageSurfaceAsync error, not continuing (Error Domain=AVFoundationErrorDomain Code=-11800 " This operation could not be completed" UserInfo=0x170675d40 {NSUnderlyingError=0x17064a950 "The operation could not be completed. ("OSStatus" error -16800.)", NSLocalizedFailureReason=An unknown error occurred (-16800), NSLocalizedDescription=This operation could not be completed})

It seems that the photo is not completed.
But after unlocking the screen, I saw that the camera has entered the preview interface, but the interface is completely black.
Then click the "Use Photo" button, and the problem reappears:

* setObjectForKey: object cannot be nil (key: UIImagePickerControllerOriginalImage)
(null)
((
0 CoreFoundation 0x000000018304c2f4 + 160
1 libobjc.A.dylib 0x00000001948780e4 objc_exception_throw + 60
2 CoreFoundation 0x0000000182f35428 + 972
3 PhotoLibrary 0x000000018e8604e8 + 772
4 PhotoLibrary 0x000000018e860188 PLNotifyImagePickerOfImageAvailability + 28
5 PhotoLibrary 0x000000018e8ad728 + 308
6 PhotoLibrary 0x000000018e8ad540 + 596
7 UIKit 0x0000000187ac1404 + 96
8 GDTaxService 0x00000001000790c4 -[UIControl(SVPreventRepeat) _sv_sendAction:to:forEvent:] + 568
9 UIKit 0x0000000187aaa4e0 + 612
10 UIKit 0x0000000187ac0da0 + 592
11 UIKit 0x0000000187ac0a2c + 700
12 UIKit 0x0000000187ab9f68 + 684
13 UIKit 0x0000000187a8d18c + 264
14 UIKit 0x0000000187d2e324 + 15424
15 UIKit 0x0000000187a8b6a0 + 1716
16 CoreFoundation 0x0000000183004240 + 24
17 CoreFoundation 0x00000001830034e4 + 264
18 CoreFoundation 0x0000000183001594 + 712
19 CoreFoundation 0x0000000182f2d2d4 CFRunLoopRunSpecific + 396
20 GraphicsServices 0x000000018c7436fc GSEventRunModal + 168
21 UIKit 0x0000000187af2fac UIApplicationMain + 1488
22 GDTaxService 0x000000010010f758 main + 124
23 libdyld.dylib 0x0000000194ef6a08 + 4
)

To analyze the steps to reproduce the problem, the cause of the problem should be that the lock screen caused the application to enter the background while the photo was in progress, and the photo was not completed, so the first problem occurred; but the photo program just captured the error and did not process it, so the camera interface After the error, I still entered the preview interface, but the photo object was nil. At this time, click "Use Photo" and the above problem occurred.

Try to solve:
1. According to a reply in stackoverflow, judge the status of the application before taking a picture:

if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
        [self takePicture];
    }

There is no effect, because it takes a long time to take pictures after the flash is turned on. As long as you press the camera button first, the judgment here will have no effect. Lock the screen when the flash is on, and the problem will still occur.
2. Customize the camera interface, draw the interface yourself and complete the function code of "use photos"; the
same does not work.
If you customize the camera interface, under the same operation steps, before the photo is returned to the custom interface, the system's "use photo" related code has been triggered by default, so this problem cannot be got rid of.
Third, the flash is disabled, reducing the chance of the problem recurs
after disabling flash, camera time is very short, the basic problem is difficult to reproduce.

Guess you like

Origin blog.csdn.net/jhq1990/article/details/53127614