Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController crashing on force touch?

With iOS 9, all of my UIImagePickerControllers are now crashing if I do a force touch on the presented images. Error message is :

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSObject previewingContext:viewControllerForLocation:]: unrecognized selector sent to class 0x1a0752020'

I guess this is an Apple bug, but has anybody a work around ?

like image 203
AirXygène Avatar asked Oct 25 '15 16:10

AirXygène


2 Answers

Answer is not clear way to fix issuse. And you can get a reject from apple by using Private API.

PUPhotoGridViewController 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, commit viewControllerToCommit: UIViewController) {

    }
}
like image 95
Antigp Avatar answered Oct 05 '22 01:10

Antigp


Here's a workaround: https://gist.github.com/nolanw/bd0a8997632fe92a9f83 (warning: swizzles a method on a private class, which should probably make you queasy). Stick those files in your project, then call MSDPreventImagePickerCrashOn3DTouch from somewhere (e.g. -applicationDidFinishLaunching:…).

The issue seems to be that a private class named PUPhotosGridViewController calls the UIViewControllerPreviewing method on its superclass, which does not implement that method. The workaround swizzles the offending method and tries to call the original implementation, but it swallows the exception so we don't crash. Hopefully, by doing it this way, if/when it gets fixed then the workaround doesn't affect that fix.

like image 28
nolanw Avatar answered Oct 05 '22 01:10

nolanw