My app is crashing when i paste some copied text in UITextView. This crash occurs only on iOS15
0 CoreFoundation 0x00007fff203feba4 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff201a1be7 objc_exception_throw + 48
2 Foundation 0x00007fff20753aa2 _userInfoForFileAndLine + 0
3 UIKitCore 0x00007fff254164a5 -[_UITextKitTextPosition compare:] + 235
4 UIKitCore 0x00007fff254097b4 -[UITextInputController comparePosition:toPosition:] + 85
5 UIKitCore 0x00007fff2542ac7d -[UITextView comparePosition:toPosition:] + 85
6 UIKitCore 0x00007fff253d0251 -[UITextPasteController _clampRange:] + 634
7 UIKitCore 0x00007fff253d09c4 __87-[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:]_block_invoke + 40
8 UIKitCore 0x00007fff253d0bcc __87-[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:]_block_invoke.174 + 184
9 UIKitCore 0x00007fff25412629 -[UITextInputController _pasteAttributedString:toRange:completion:] + 471
10 UIKitCore 0x00007fff253d092a -[UITextPasteController _performPasteOfAttributedString:toRange:forSession:completion:] + 726
11 UIKitCore 0x00007fff253cfc07 __49-[UITextPasteController _executePasteForSession:]_block_invoke + 299
12 libdispatch.dylib 0x00007fff2011265a _dispatch_call_block_and_release + 12
13 libdispatch.dylib 0x00007fff2011383a _dispatch_client_callout + 8
14 libdispatch.dylib 0x00007fff20120c88 _dispatch_main_queue_callback_4CF + 1075
15 CoreFoundation 0x00007fff2036c84d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
16 CoreFoundation 0x00007fff203670aa __CFRunLoopRun + 2772
17 CoreFoundation 0x00007fff203660f3 CFRunLoopRunSpecific + 567
18 GraphicsServices 0x00007fff2c995cd3 GSEventRunModal + 139
19 UIKitCore 0x00007fff25059f42 -[UIApplication _run] + 928
20 UIKitCore 0x00007fff2505eb5e UIApplicationMain + 101
2
Answers
Conform your view controller to
UITextPasteDelegate
:And set past delagete:
Then implement
textPasteConfigurationSupporting
function:I found a possible solution that worked for me. If you use UITextView within a table view and you also implemented prepareForReuse for a cell which contains UITextView. Make sure you set the UITextView.text value to nil in prepareForReuse. In my case I did that later (not in prepareForReuse) and this somehow caused some inconsistency issues regarding "pos" when pasting leading to a crash.