if ([MyView respondsToSelector:@selector(traitCollection)] &&
[MyView.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
MyView.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
return YES;
}
My point is, if you are supporting iOS 7 and iOS 8 as well, remember to check for both the conditions: [MyView respondsToSelector:@selector(traitCollection)]
and [MyView.traitCollection respondsToSelector:@selector(forceTouchCapability)]
.
If you keep the first check, the app works fine on iOS 7 but crashes on iOS 8.
Basically, Apple introduced traitCollection
property in iOS 8 but added forceTouchCapability
property only in iOS 9.
from UITraitCollection.h:
@property (nonatomic, readonly) UITraitCollection *traitCollection NS_AVAILABLE_IOS(8_0);
@property (nonatomic, readonly) UIForceTouchCapability forceTouchCapability NS_AVAILABLE_IOS(9_0);
PS: Learnt it the hard way, after app started to crash on App Store.
forceTouchCapability
. This link seems helpful/relevant: pinkstone.co.uk/… – InsphereforceTouchCapability
only checks to see if the device is iOS 9 or greater? – ArnoneBOOL
. – Arnone