From IOS 16 onwards my app which uses UITextView in iOS for editing, started crashing for a number of users with error

App crashes with error "Fatal Exception: NSInvalidArgumentException -[<NSTextContentStorage: 0x281dc68a0> locationFromLocation:withOffset:] received invalid location (null)"

**After researching we found that this could be an issue with the new textkit engine of UITextView.

And to restore the previous behavior and avoid the crash, we explicitly set the UITextView to use TextKit 1.

But unfortunately, even after this change, this crash is not gone and users are still facing this issue.

I'm also adding complete stack trace of this crash


Fatal Exception: NSInvalidArgumentException 0 CoreFoundation        0x9e88 __exceptionPreprocess

1 libobjc.A.dylib        0x178d8 objc_exception_throw

2 CoreFoundation        0xf9c58 __CFDictionaryCreateGeneric

3 UIFoundation         0x220e0 -[NSTextContentStorage locationFromLocation:withOffset:]

4 UIFoundation         0x9f104 -[NSTextLineFragment textLineFragmentRange]

5 UIFoundation         0x86e70 __95-[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:]_block_invoke

6 CoreFoundation        0xa3a0 NSARRAY_IS_CALLING_OUT_TO_A_BLOCK

7 CoreFoundation        0x910e0 -[__NSArrayI  enumerateObjectsWithOptions:usingBlock:]

8 UIFoundation         0x86cfc -[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:]

9 UIFoundation         0x86eb4 -[NSTextLayoutManager lineFragmentRangeForPoint:inContainerAtLocation:]

10 UIFoundation         0x7e6ec -[NSTextSelectionNavigation _lineFragmentInfoForPoint:inContainerAtLocation:bounds:layoutOrientation:beforeLineFragment:afterLineFragment:lineFragmentRange:]

11 UIFoundation         0x815d8 -[NSTextSelectionNavigation textSelectionsInteractingAtPoint:inContainerAtLocation:anchors:modifiers:selecting:bounds:]

12 UIKitCore           0x98f5d8 -[_UITextKit2LayoutController cursorPositionAtPoint:inContainer:]

13 UIKitCore           0xf33d88 -[UITextInputController _characterPositionForPoint:]

14 UIKitCore           0xf4a2cc -[UITextView closestPositionToPoint:]

15 UIKitCore           0xedef5c -[UITextSelectionInteraction tappedToPositionCursorWithGesture:atPoint:granularity:completionHandler:]

16 UIKitCore           0xedecc8 -[UITextSelectionInteraction _checkForRepeatedTap:gestureLocationOut:]

17 UIKitCore           0xedf524 -[UITextSelectionInteraction _handleMultiTapGesture:]

18 UIKitCore           0x24ed54 -[UIApplication sendAction:to:from:forEvent:]

19 UIKitCore           0x9448fc -[UITextMultiTapRecognizer onStateUpdate:]

20 UIKitCore           0xbe874 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:]

21 UIKitCore           0x42c9f0 _UIGestureRecognizerSendTargetActions

22 UIKitCore           0x1a60a4 _UIGestureRecognizerSendActions

23 UIKitCore           0x86a14 -[UIGestureRecognizer _updateGestureForActiveEvents]

24 UIKitCore           0x1328d8 _UIGestureEnvironmentUpdate

25 UIKitCore           0x9b7e14 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:]

26 UIKitCore           0xf731c -[UIGestureEnvironment _updateForEvent:window:]

27 UIKitCore           0xfbc74 -[UIWindow sendEvent:]

28 UIKitCore           0xfaf44 -[UIApplication sendEvent:]

29 Aspen             0x6963c0 TimerApplication.sendEvent(_:) ()

30 Aspen             0x696834 @objc TimerApplication.sendEvent(_:) ()

31 UIKitCore           0xfa600 __dispatchPreprocessedEventFromEventQueue

Also, the app was re-released in Appstore with Xcode 14.0. Any help would be appreciated.

From IOS 16 onwards my app which uses UITextView in iOS for editing, started crashing for a number of users with error
 
 
Q