UIEditMenuInteraction 闪退

iOS16 任何输入控件,在不调试状态双击弹出粘贴框时闪退,什么原因? 已崩溃:com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000020

keyboard_arrow_up 0 libobjc.A.dylib objc_retain_x0 + 16 1 libobjc.A.dylib objc_retain + 16 arrow_right 2 UIKitCore -[_UIContextMenuInteractionBasedTextContextInteraction _editMenuForCurrentSelectionWithSuggestedActions:isEditMenu:] + 168 3 UIKitCore -[_UIContextMenuInteractionBasedTextContextInteraction _querySelectionCommandsForConfiguration:suggestedActions:completionHandler:] + 448 4 UIKitCore -[_UIContextMenuInteractionBasedTextContextInteraction _editMenuInteraction:menuForConfiguration:suggestedActions:completionHandler:] + 140 5 UIKitCore -[UIEditMenuInteraction _prepareMenuAtLocation:configuration:completionHandler:] + 280 6 UIKitCore -[UIEditMenuInteraction presentEditMenuWithConfiguration:] + 224 7 UIKitCore -[_UIContextMenuInteractionBasedTextContextInteraction presentSelectionCommandsWithConfiguration:] + 80 8 UIKitCore -[UITextSelectionView _presentEditMenuWithPreferredDirection:replacements:] + 80 9 UIKitCore -[UITextSelectionView _showCommandsWithReplacements:isForContextMenu:forDictation:arrowDirection:] + 904 10 UIKitCore __77-[UITextSelectionView _showCommandsWithReplacements:forDictation:afterDelay:]_block_invoke + 228 11 UIKitCore -[UITextSelectionView _showCommandsWithReplacements:forDictation:afterDelay:] + 332 12 UIKit -[UITextSelectionViewAccessibility showCommandsWithReplacements:] + 96 13 UIKitCore __51-[UITextSelectionView deferredUpdateSelectionRects]_block_invoke + 32 14 CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 36 15 CoreFoundation __CFRunLoopDoObservers + 532 16 CoreFoundation __CFRunLoopRun + 808 17 CoreFoundation CFRunLoopRunSpecific + 612 18 GraphicsServices GSEventRunModal + 164 19 UIKitCore -[UIApplication _run] + 888 20 UIKitCore UIApplicationMain + 340

同行,你好,我估计也遇到类似的问题了,经排查: 是一个UITextField的分类导致的,代码如下:必现:

#import "UITextField+Select.h"

@implementation UITextField (Select)

  • (NSRange)selectedRange

{

    UITextPosition *beginning = self.beginningOfDocument;

    UITextRange *selectedRange = self.selectedTextRange;

    UITextPosition *selectionStart = selectedRange.start;

    UITextPosition *selectionEnd = selectedRange.end;

    NSInteger location = [self offsetFromPosition:beginning toPosition:selectionStart];

    NSInteger length = [self offsetFromPosition:selectionStart toPosition:selectionEnd];

    return NSMakeRange(location, length);

}

  • (void)selectedText

{

    UITextRange *range = [self textRangeFromPosition:self.beginningOfDocument toPosition:self.endOfDocument];

    [self setSelectedTextRange:range];

}

  • (void)setSelectedRange:(NSRange)range

{

    UITextPosition *beginning = self.beginningOfDocument;

    UITextPosition *startPosition = [self positionFromPosition:beginning offset:range.location];

    UITextPosition *endPosition = [self positionFromPosition:beginning offset:NSMaxRange(range)];

    UITextRange *selectionRange = [self textRangeFromPosition:startPosition toPosition:endPosition];

    [self setSelectedTextRange:selectionRange];

}

@end

iOS16以后的机型(真机或者模拟器)都会,我也搞不懂啥情况,debug模式就是定位不到,[捂脸]才一个个第三方文件排查,新建的demo,uitextfield的输入框,没问题,加了那个文件,即使没用,加入项目也会导致,关闭项目,运行iOS16的设备,双击输入框,基本就会crash。

UIEditMenuInteraction 闪退
 
 
Q