UITextView startInteractionWithLinkAtPoint crash only for iOS 11

This way, I am crashing in the UItextview while the user is interacting with the URL link. All crash reports have only iOS version 11. This seems like a well-known bug in iOS 9, but there are no iOS versions for one report below 11, and in the report I found an interesting line:

UITextGestureClusterLinkInteract smallDelayRecognizer: 

which comes with iOS 11 ( http://developer.limneos.net/?ios=11.0&framework=UIKit.framework&header=UITextGestureClusterLinkInteract.h ). Anyway, now I fixed it with

 @available(iOS 10.0, *) func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { UIApplication.shared.openURL(URL) return false } 

which is not so great because you are losing the action menu. My assumption was that it was caused by 3D touch (for example, with a long press in previous versions), but if I detect 3D touch (75% or even 50% of maximum strength) and disables link interaction for this particular gesture - the problem still appears, Does anyone have some experience in this particular problem and a more elegant way to solve it?

+5
source share
2 answers

The crash is caused by UIDragInteraction / UITextDragAssistant on iOS 11.0 and 11.1. It is fixed on iOS 11.2. Subclassing your UITextView and disabling drag and drop gestures will prevent a crash for any version of iOS:

 class NoDragDropTextView: UITextView { override func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) { // required to prevent drag and drop gestures // also prevents a crash on iOS 11.0-11.1 gestureRecognizer.isEnabled = false super.addGestureRecognizer(gestureRecognizer) } } 
+1
source

I tested and solved this problem.

This is a workaround in my production code. Disable .preview interaction due to failures only in this state.

 func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { switch interaction { case .presentActions, .invokeDefaultAction: return handleLinkURL(url: URL) case .preview: return false } } 
0
source

Source: https://habr.com/ru/post/1272601/


All Articles