UIKeyCommand incorrectly responds to respondsToSelector:

Originator:futuretap
Number:rdar://26532500 Date Originated:28-May-2016 05:50 PM
Status:Closed/Behaves Correctly Resolved:
Product:iOS SDK Product Version:9.3.2
Classification:Other Bug Reproducible:Always
 
Summary:
Apps with a deployment target of iOS 7 or iOS 8 using UIKeyCommand need to check if UIKeyCommand supports +keyCommandWithInput:modifierFlags:action:discoverabilityTitle:

Checking with +instancesRespondToSelector: or -respondsToSelector: returns NO on iOS 9.3.2 even though iOS 9 supports this method. In a typical use case the app would fallback to the old iOS 7+ method +keyCommandWithInput:modifierFlags:action: thereby losing the discoverabilityTitle.

Steps to Reproduce:

# on iOS 9.3.2:

(lldb) p (BOOL) [UIKeyCommand instancesRespondToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]
(lldb) p (BOOL) [[[UIKeyCommand alloc] init] respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]

Expected Results:
(lldb) p (BOOL) [UIKeyCommand instancesRespondToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]
(BOOL) $6 = YES
(lldb) p (BOOL) [[[UIKeyCommand alloc] init] respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]
(BOOL) $7 = YES

Actual Results:
(lldb) p (BOOL) [UIKeyCommand instancesRespondToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]
(BOOL) $6 = NO
(lldb) p (BOOL) [[[UIKeyCommand alloc] init] respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)]
(BOOL) $7 = NO

Regression:
This is a regression from iOS 9.3.1 to 9.3.2.

Note:
Even if iOS 9.3.2 claims it doesn't respond to the +keyCommandWithInput:modifierFlags:action:discoverabilityTitle: selector, it actually does:

(lldb) po [UIKeyCommand keyCommandWithInput:@"a" modifierFlags:UIKeyModifierCommand action:@selector(performKeyCommand:) discoverabilityTitle:@"Select All"]
<UIKeyCommand: 0x15f154f0>

Comments

It totally escaped me…

that testing for a class method doesn't work like this.

keyCommandWithInput:modifierFlags:action:discoverabilityTitle: is a class method of UIKeyCommand, testing for [UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] returns YES.

The fact that my wrong code worked in 9.3.1 lead me to false conclusions.

By futuretap at June 3, 2016, 9:13 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!