我们的应用程序查找 Foundation 崩溃,仅在 iOS11 中。怎么解决?
Fatal Exception: NSRangeException
NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds
0 CoreFoundation 0x184f8bd38 __exceptionPreprocess
1 libobjc.A.dylib 0x1844a0528 objc_exception_throw
2 CoreFoundation 0x184f8bc80 -[NSException initWithCoder:]
3 Foundation 0x18587c168 -[NSMutableRLEArray replaceObjectsInRange:withObject:length:]
4 Foundation 0x18588262c -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:]
5 CoreFoundation 0x184e65bec -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]
6 UIKit 0x18ec677b8 -[UILayoutManagerBasedDraggableGeometry draggableObjectsForTextRange:]
我可以在 iOS 13.0 beta 4 中使用一个示例应用程序来重现它,该应用程序显示一个带有特殊属性字符串(包括链接)的 UITextView。点击按住或拖动链接时会崩溃。
NSMutableAttributedString *aString = [[NSMutableAttributedString alloc] initWithString:@""];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [[UIImage imageNamed:@"weblink"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
attachment.bounds = CGRectMake(0, 0, 15, 15);
[aString appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
[aString appendAttributedString:[[NSAttributedString alloc] initWithString:@" More Information"]];
[aString addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"https://www.apple.com"] range:NSMakeRange(0, aString.length)];
self.textView.attributedText = aString;
在 反馈助手上提交为 FB6738178。
我在使用UITextInput的方法时遇到了同样的问题
replaceRange:(UITextRange *)range withText:(NSString *)text;
我找不到最佳解决方案,但我通过避免使用特殊字符来修复崩溃
'
在replaceRange方法的第二个参数中
ps:该问题仅出现在iOS 11中
看看这是否可以帮助你,图标不应该出现在超链接的内容中,否则系统会出现越界错误 例如:
这是一个链接。 这个会出错,但是一旦你像这样改变图标位置: 这是一个链接。 没事的。