【问题标题】:iOS11 Crash in NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of boundsNSMutableRLEArray 中的 iOS11 崩溃 replaceObjectsInRange:withObject:length:: 越界
【发布时间】:2017-10-26 03:15:36
【问题描述】:

我们的 App Find a Foundation crash,仅在 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:]

【问题讨论】:

  • 在 NSMutableArray 中放一些替换对象动作的代码。
  • 谢谢。但是我们不知道是什么代码触发了这个崩溃。我们的代码使用replaceObjectAtIndex这么多地方。
  • 在 XCode 中转到“调试菜单”,然后将光标移动到“断点”选项上。在其中单击“创建异常断点”。然后再次运行并执行导致崩溃的相同步骤。它会卡在发生崩溃的地方。
  • 我们在 Fabric 网站上发现了这个崩溃。它从我们的应用程序收集我们的崩溃信息。我们无法通过测试重现此崩溃。
  • 我也有同样的问题,请问有什么更新吗?

标签: crash ios11 foundation


【解决方案1】:

我可以在 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。

【讨论】:

  • 不,也请提交错误。自 iOS 13.2 beta 4 起,它仍处于打开状态。
  • 至少在 iOS 12.4-14.5 中仍然是一个错误。从链接中删除附件(因此,不调用addAttribute:value:range:)可防止长按崩溃
【解决方案2】:

我在使用 UITextInput 方法时遇到了同样的问题

replaceRange:(UITextRange *)range withText:(NSString *)text;


我找不到最佳解决方案,但我通过避免使用特殊字符来修复崩溃

'

在replaceRange方法的第二个参数中

ps:该问题仅出现在 iOS 11 中

【讨论】:

    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2020-08-29
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    相关资源
    最近更新 更多