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 ?
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.
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) {
}
}
Apples bug unfortunately. You just have to wait for a fix.
https://forums.developer.apple.com/thread/21932