UITextView startInteractionWithLinkAtPoint仅崩溃iOS 11 [英] UITextView startInteractionWithLinkAtPoint crash iOS 11 only
问题描述
因此,当用户与URL链接进行交互时,我在UItextview中遇到崩溃。所有崩溃报告仅限iOS版本11。
这看起来像是iOS 9中众所周知的错误,但是没有单个报告iOS版本低于11,而且在报告中我发现有趣的行:
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 is no single report iOS versions lower than 11, and also in report I found interesting line:
UITextGestureClusterLinkInteract smallDelayRecognizer:
随iOS 11附带( http://developer.limneos.net/?ios= 11.0&安培;框架= UIKit.framework&安培;首标= UITextGestureClusterLinkInteract.h )。
无论如何,现在我修复它
which came with iOS 11 (http://developer.limneos.net/?ios=11.0&framework=UIKit.framework&header=UITextGestureClusterLinkInteract.h). Anyway, for 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
}
这不是很酷,因为你丢失了动作表菜单。
我的假设是它是由3D触摸引起的(比如先前版本中的长按),但如果我检测到3D触摸(75%,甚至是最大力的50%)并禁用此特定手势的链接交互 - 问题仍然出现。
有没有人对这个特殊问题有一些经验和更优雅的解决方法?
which is not so cool, because you lose action sheet menu. My assumption was that it is caused by 3D touch (like by long press in previous versions), but if I detect 3D touch (75%, or even 50% of maximum force) and disable link interaction for this specific gesture - issue still appears. Does anybody has some experience with this particular issue and more elegance way of solving it?
推荐答案
导致崩溃iOS 11.0和11.1上的 UIDragInteraction
/ UITextDragAssistant
。它在iOS 11.2上修复。对UITextView进行子类化并禁用拖放手势可以防止任何iOS版本崩溃:
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)
}
}
这篇关于UITextView startInteractionWithLinkAtPoint仅崩溃iOS 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!