Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone 6s - iOS 9.1 crashing on [UICollectionViewController previewingContext:viewControllerForLocation:]

This is a pretty goofy stack trace, because looking around, the only thing I can think of is that the iPhone 6s user is trying to 3D-touch something, and my gesture recognizer (somewhere, I don't know which one because it doesn't tell me which line or even which controller) doesn't know how to handle it? I haven't added any 3D-touch gesture recognizers nor am I implementing 3D-touch interactions anywhere.

I've targeted iOS 8 in this build, and I don't have an iPhone 6s to test with unfortunately so can't really reproduce it.

Thoughts on what might be causing it, how to narrow down where/what and how to reproduce, and how to handle the exception?

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x18586cf48 __exceptionPreprocess
1  libobjc.A.dylib                0x19ad17f80 objc_exception_throw
2  CoreFoundation                 0x185873b54 __CFExceptionProem
3  UIKit                          0x18b63438c -[UICollectionViewController previewingContext:viewControllerForLocation:]
4  UIKit                          0x18b187d7c -[_UIViewControllerPreviewSourceViewRecord previewInteractionController:viewControllerForPreviewingAtPosition:inView:presentingViewController:]
5  UIKit                          0x18b43cd4c -[UIPreviewInteractionController startInteractivePreviewAtLocation:inView:]
6  UIKit                          0x18b43d848 -[UIPreviewInteractionController startInteractivePreviewWithGestureRecognizer:]
7  UIKit                          0x18b43e8c0 -[UIPreviewInteractionController _handleRevealGesture:]
8  UIKit                          0x18b37b330 _UIGestureRecognizerSendTargetActions
9  UIKit                          0x18afa4b5c _UIGestureRecognizerSendActions
10 UIKit                          0x18ae3285c -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
11 UIKit                          0x18b37c70c ___UIGestureRecognizerUpdate_block_invoke898
12 UIKit                          0x18adf18b8 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks
13 UIKit                          0x18adee63c _UIGestureRecognizerUpdate
14 UIKit                          0x18ae306cc -[UIWindow _sendGesturesForEvent:]
15 UIKit                          0x18ae2fcc8 -[UIWindow sendEvent:]
16 UIKit                          0x18ae004a4 -[UIApplication sendEvent:]
17 UIKit                          0x18adfe76c _UIApplicationHandleEventQueue
18 CoreFoundation                 0x185824544 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
19 CoreFoundation                 0x185823fd8 __CFRunLoopDoSources0
20 CoreFoundation                 0x185821cd8 __CFRunLoopRun
21 CoreFoundation                 0x185750ca0 CFRunLoopRunSpecific
22 GraphicsServices               0x190cd4088 GSEventRunModal
23 UIKit                          0x18ae68ffc UIApplicationMain
24 XXXXXXXXXX                     0x10013739c main (main.m:16)
25 libdyld.dylib                  0x19b55a8b8 start
like image 638
brandonscript Avatar asked Nov 18 '15 07:11

brandonscript


3 Answers

PUPhotoGridViewController(used in UIImagePickerController) is a simple UICollectionViewController and you can write extension for not implemented method.

extension UICollectionViewController: UIViewControllerPreviewingDelegate {
    public func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
        return nil;
    }

    public func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {

    }
}
like image 127
Antigp Avatar answered Sep 20 '22 21:09

Antigp


Do you use UIImagePickerController somewhere in your app? There's a known issue with it and 3D Touch: UIImagePickerController crashing on force touch?

Force-touching a photo in UIImagePickerController seems to crash any app. I guess we'll have to wait until Apple fixes this.

like image 29
Vlas Voloshin Avatar answered Sep 20 '22 21:09

Vlas Voloshin


Thanks for @Antigp'answer!

Here is OC version:

Header

@interface UICollectionViewController (FixCrash) <UIViewControllerPreviewingDelegate>
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location;
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
     commitViewController:(UIViewController *)viewControllerToCommit;
@end

Implementation

@implementation UICollectionViewController (FixCrash)
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
    return nil;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
         commitViewController:(UIViewController *)viewControllerToCommit {
    return;
}
@end
like image 25
phoenixxyang Avatar answered Sep 21 '22 21:09

phoenixxyang