UITextView startInteractionWithLinkAtPoint crash iOS 11 only

后端 未结 2 1932
遥遥无期
遥遥无期 2020-12-10 16:20

So I experience crash in UItextview while user interacts with URL link there. All crash reports have iOS version 11 only. This looks like well-known bug in iOS 9, but there

相关标签:
2条回答
  • 2020-12-10 16:58

    I experienced and solved this problem.

    This is workaround in my production code. Disable interaction .preview state because of crashes only this state occurs.

    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 讨论(0)
  • 2020-12-10 17:14

    A crash is caused by a 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 the crash for any iOS version:

    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)
        }
    }
    
    0 讨论(0)
提交回复
热议问题