iOS 15 crash: Fatal Exception: NSInternalInconsistencyException Invalid parameter not satisfying: pos

Hi,

I've seen a couple of crashes in iOS 15 that I've never seen before.

From what I can tell it seems to be caused when a user pastes text from one application to another.

Could somebody help me verify that:

  1. The crash is caused by pasting from another app.
  2. The crash is caused by an iOS defect and not a defect in my app.
code-blockFatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x91cac __exceptionPreprocess
1  libobjc.A.dylib                0x14758 objc_exception_throw
2  Foundation                     0x12361c _userInfoForFileAndLine
3  UIKitCore                      0x10b6ffc -[_UITextKitTextPosition compare:]
4  UIKitCore                      0x2065c -[UITextInputController comparePosition:toPosition:]
5  UIKitCore                      0x10c1b5c -[UITextView comparePosition:toPosition:]
6  UIKitCore                      0x108de4c -[UITextPasteController _clampRange:]
7  UIKitCore                      0x108e5cc __87-[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:]_block_invoke
8  UIKitCore                      0x108e7c8 __87-[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:]_block_invoke.174
9  UIKitCore                      0x10b35e4 -[UITextInputController _pasteAttributedString:toRange:completion:]
10 UIKitCore                      0x108e518 -[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:]
11 UIKitCore                      0x108d820 __49-[UITextPasteController _executePasteForSession:]_block_invoke
12 libdispatch.dylib              0x632ec _dispatch_call_block_and_release
13 libdispatch.dylib              0x642f0 _dispatch_client_callout
14 libdispatch.dylib              0x109a0 _dispatch_main_queue_callback_4CF$VARIANT$mp
15 CoreFoundation                 0x4d7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
16 CoreFoundation                 0xb0f8 __CFRunLoopRun
17 CoreFoundation                 0x1dd8c CFRunLoopRunSpecific
18 GraphicsServices               0x19a0 GSEventRunModal
19 UIKitCore                      0x4ee018 -[UIApplication _run]
20 UIKitCore                      0x28229c UIApplicationMain
21 TOFS_AppStore                  0x71b0 main + 18 (AppDelegate.swift:18)
22 ???                            0x1030f0190 (Missing)
Answered by bduggan in 701580022

In my case this was caused by users copying and pasting into a UITableView Form. The solution was to not use cell reuse. This can be easily accomplished by adding something like the row number to the cell identifier string.

The crash is caused by an iOS defect and not a defect in my app. > Does your code contain any code to do with copy & paste programmatically?

No. There's absolutely no code in my application to do with copying and pasting programmatically.

Does your project has any third party libraries? If so, have you checked all of them are free from copy & paste code?

Yes, I'm using a few third party libraries. I am certain that none of them have any copy & paste code.

Seems you have checked all the source code of the libraries used. Then I have no clue. Hope your issue will solved soon.

I am experiencing the same issue. Did you ever figure out what was happening?

Accepted Answer

In my case this was caused by users copying and pasting into a UITableView Form. The solution was to not use cell reuse. This can be easily accomplished by adding something like the row number to the cell identifier string.

I do have the same issue. It somewhat randomly happens on copy/paste in UITextFields in UITableViewCells.

I can also catch it in the debugger and I get the following: *** Assertion failure in -[_UITextKitTextPosition compare:], UITextKitTextViewEditingSupport.m:43. This does seem to be an iOS issue and not an issue in my code.

Others have also written about this issue:

Some people are suggesting to implement UITextPasteDelegate to work around the issue. In a large app implementing UITextPasteDelegate on all textfields is very cumbersome and I don't think that this is really the solution to this problem.

Has anyone found a better solution for this issue?

Will it eventually be fixed in a future iOS update?

Make sure you set the .text value to nil in prepareForReuse when using UITextView within a Cell. In my case not setting UITextView.text to nil somehow caused some inconsistency issues regarding "pos" when pasting text, leading to a crash.

We haven't seen any instances of this crash in our app on iOS 15.5, so I think it may have been finally been fixed in that release of iOS.

iOS 15 crash: Fatal Exception: NSInternalInconsistencyException Invalid parameter not satisfying: pos
 
 
Q