Forward delete calls selectedTextRange on class that does not adopt UITextInput

Number:rdar://15114422 Date Originated:30-Sep-2013
Status:Open Resolved:
Product:iOS SDK Product Version:7.0.2
Classification: Reproducible:Always
When the user types forward delete using an external keyboard, an attempt is made to access the selectedTextRange property of the class that is first responder even if it does not adopt the UITextInput protocol.

Steps to Reproduce:
1. Open the project in the attached zip in Xcode
2. Run the project on iOS7 using the simulator
3. Type fn-backspace
4. App crashes

Expected Results:
No attempt is made to access the selectedTextRange property on a class that does not adopt the UITextInput protocol

Actual Results:
An attempt is made to access the selectedTextRange property, even though the class does not adopt the UITextInput protocol. This typically leads to a crash when the unrecognized selector is sent to the instance:

2013-09-30 21:36:23.790 UITextInputCrash[15191:a0b] -[UITextInputCrashViewController selectedTextRange]: unrecognized selector sent to instance 0xa009770
2013-09-30 21:36:23.792 UITextInputCrash[15191:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextInputCrashViewController selectedTextRange]: unrecognized selector sent to instance 0xa009770'
*** First throw call stack:
	0   CoreFoundation                      0x017485e4 __exceptionPreprocess + 180
	1   libobjc.A.dylib                     0x014b78b6 objc_exception_throw + 44
	2   CoreFoundation                      0x017e5903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
	3   CoreFoundation                      0x0173890b ___forwarding___ + 1019
	4   CoreFoundation                      0x017384ee _CF_forwarding_prep_0 + 14
	5   UIKit                               0x00640dfc -[UIResponder(UITextInput_Internal) _deleteForwardAndNotify:] + 59
	6   UIKit                               0x004076cd -[UIKeyboardImpl deleteForwardAndNotify:] + 92
	7   UIKit                               0x00400062 -[UIKeyboardImpl handleKeyCommand:repeatOkay:] + 2628
	8   UIKit                               0x00414aae -[UIKeyboardImpl handleKeyEvent:executionContext:] + 1288
	9   UIKit                               0x0041450f __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 51
	10  UIKit                               0x009371b8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
	11  UIKit                               0x0093785f -[UIKeyboardTaskQueue addTask:] + 144
	12  UIKit                               0x004144d4 -[UIKeyboardImpl handleKeyEvent:] + 227
	13  UIKit                               0x0023dfbb -[UIApplication _handleKeyUIEvent:] + 330
	14  UIKit                               0x00384634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
	15  UIKit                               0x00384634 -[UIResponder(Internal) _handleKeyUIEvent:] + 59
	16  UIKit                               0x0023de6a -[UIApplication handleKeyUIEvent:] + 84
	17  UIKit                               0x0023de0e -[UIApplication handleKeyHIDEvent:] + 458
	18  UIKit                               0x00225c8c _UIApplicationHandleEventQueue + 2954
	19  CoreFoundation                      0x016d18af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
	20  CoreFoundation                      0x016d123b __CFRunLoopDoSources0 + 235
	21  CoreFoundation                      0x016ee30e __CFRunLoopRun + 910
	22  CoreFoundation                      0x016edb33 CFRunLoopRunSpecific + 467
	23  CoreFoundation                      0x016ed94b CFRunLoopRunInMode + 123
	24  GraphicsServices                    0x036859d7 GSEventRunModal + 192
	25  GraphicsServices               

iOS 7.0.2


iPhone, iPad and iOS simulator running iOS 7. The problem does not appear to occur on earlier version of iOS, i.e. I believe this is a regression.

'' was successfully uploaded.


In attempting to work around the problem, I have discovered that inputDelegate is also called.

A work around is to declare two properties on the class that will be the first responder:

@property UITextRange *selectedTextRange; @property id inputDelegate;

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!