I've been able to replicate this issue in my code. This seems to be a bug in Apple's code and is a timing issue.
I haven't replicated it by clicking to actually take a photo, but I can replicate it when I hit cancel. You can try doing this in your code and seeing if it works for you. Open up the camera to take a photo and then pinch to zoom. You'll get a little zoom slider show up on the screen. After about 4-5 second that zoom slide fades away. This is where timing comes in. If you click cancel just as it starts to fade you can get it to crash.
My assumption is that Apple has an animation block in which it fades the zoom slider. In the completion of that animation it calls didHideZoomSlider:
without checking it's reference to the image picker.
I think it is easier to replicate on my cancel code because it was very simple:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
My assumption is that since this executes so fast it is able to dismiss it in the middle of that animation. Therefore my solution is to actually delay my dismissal of the view by a small amount of time.
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
__weak typeof(self) wSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[wSelf dismissViewControllerAnimated:YES completion:nil];
});
}
I don't think this "fixes" the issue, but reduces it such that I'm unable to replicate it anymore. This should be filed as a bug with Apple (which I'll do next).
Update: Sent to Apple.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…