The following error keeps coming up in my app\'s crashlytics logs
on IOS 8:
libobjc.A.dylib objc_msgSend + 5 didHideZoomSlider:
Crashed: com.apple.m
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.
I didn't have much luck with adding the delay. Crashes still occurred in my case (iOS 8 and 9.0.1).
There's an OpenRadar that suggests removing the delegate of the CAMZoomSlider
likely responsible for the crash, and this worked well for me.
User beware, though, as this manipulates a private class and may result in an App Store submission rejection...
To fix issue with delegate, subclass UIImagePickerController
and add the following:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self clearZoomSliderDelegateForClass:[self sliderClass] subviews:self.view.subviews];
}
- (void)clearZoomSliderDelegateForClass:(Class)sliderClass subviews:(NSArray *)subviews {
for (UIView *subview in subviews) {
if ([subview isKindOfClass:sliderClass] && [subview respondsToSelector:@selector(setDelegate:)]) {
[subview performSelector:@selector(setDelegate:) withObject:nil];
return;
}
else {
[self clearZoomSliderDelegateForClass:sliderClass subviews:subview.subviews];
}
}
}
- (Class)sliderClass {
for (NSString* prefix in @[@"CAM", @"CMK"]) {
Class zoomClass = NSClassFromString([prefix stringByAppendingString:@"ZoomSlider"]);
if (zoomClass != Nil) {
return zoomClass;
}
}
return Nil;
}
In iOS 9 SDK private CameraKit framework prefix changed from CAM
to CMK
(just check slider with visual debugger), so previous workaround had to be updated.
This crash may also look like this in logs:
0 libobjc.A.dylib 0x3591fae6 objc_msgSend + 6
1 Foundation 0x24d28e59 __NSFireDelayedPerform + 466
...
This is already answered, but another potential solution here would be to retain the image picker controller instance inside the view controller to avoid it being deallocated prior to apple's callback firing.