iOS: fix crash on iOS 8 due to unsupported selector

It turns out that f558bde was not enough to stop a crash when
trying to access forceTouchCapability of traitCollection. The
reason is that traitCollection is available on UIScreen starting
from iOS 8, while forceTouchCapability is available on
UITraitCollection starting from iOS 9. So only checking the former
will cause a crash when running on iOS 8.

Change-Id: I44f9fb785349694004fbf2f48fe3b85bb01d9a5a
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
bb10
Richard Moe Gustavsen 2016-01-11 11:27:19 +01:00 committed by Tor Arne Vestbø
parent e8479592c5
commit ca7f1d2197
2 changed files with 9 additions and 5 deletions

View File

@ -105,7 +105,7 @@ QIOSIntegration::QIOSIntegration()
m_touchDevice = new QTouchDevice;
m_touchDevice->setType(QTouchDevice::TouchScreen);
QTouchDevice::Capabilities touchCapabilities = QTouchDevice::Position | QTouchDevice::NormalizedPosition;
if ([mainScreen respondsToSelector:@selector(traitCollection)]) {
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_9_0) {
if (mainScreen.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
touchCapabilities |= QTouchDevice::Pressure;
}

View File

@ -286,10 +286,14 @@
QTouchDevice *touchDevice = QIOSIntegration::instance()->touchDevice();
QTouchDevice::Capabilities touchCapabilities = touchDevice->capabilities();
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
touchCapabilities |= QTouchDevice::Pressure;
else
touchCapabilities &= ~QTouchDevice::Pressure;
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_9_0) {
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
touchCapabilities |= QTouchDevice::Pressure;
else
touchCapabilities &= ~QTouchDevice::Pressure;
}
touchDevice->setCapabilities(touchCapabilities);
}