diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2015-02-06 09:29:48 +0100 |
---|---|---|
committer | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2015-02-06 11:31:41 +0000 |
commit | 35be7aecc06f6e2bfe9b6a5a267d77c94dbe3a4a (patch) | |
tree | 64fdeeaafc837d72e5104cf92a6b14b87f646f6a /src/bluetooth/osx/osxbtcentralmanager.mm | |
parent | 87d2660b0878ad08521ad10f364fbe9c3c59f7af (diff) |
Qt Bluetooth - add runtime OS version check (OS X, iOS)
Compile time check of SDK version is not sufficient if Qt is build
for older device.
Change-Id: I0e4d0baf903c6291e67462890107b0e5cc30e7c4
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/osx/osxbtcentralmanager.mm')
-rw-r--r-- | src/bluetooth/osx/osxbtcentralmanager.mm | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 2fc74e36..6e927590 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -45,6 +45,7 @@ #include <QtCore/qloggingcategory.h> +#include <QtCore/qsysinfo.h> #include <QtCore/qdebug.h> #include <algorithm> @@ -206,31 +207,33 @@ using namespace QT_NAMESPACE; } #if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_6_0) - const quint128 qtUuidData(deviceUuid.toUInt128()); - // STATIC_ASSERT on sizes would be handy! - uuid_t uuidData = {}; - std::copy(qtUuidData.data, qtUuidData.data + 16, uuidData); - const ObjCScopedPointer<NSUUID> nsUuid([[NSUUID alloc] initWithUUIDBytes:uuidData]); - if (!nsUuid) { - qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate NSUUID identifier"; - return QLowEnergyController::ConnectionError; - } + if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_6_0)) { + const quint128 qtUuidData(deviceUuid.toUInt128()); + // STATIC_ASSERT on sizes would be handy! + uuid_t uuidData = {}; + std::copy(qtUuidData.data, qtUuidData.data + 16, uuidData); + const ObjCScopedPointer<NSUUID> nsUuid([[NSUUID alloc] initWithUUIDBytes:uuidData]); + if (!nsUuid) { + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate NSUUID identifier"; + return QLowEnergyController::ConnectionError; + } - [uuids addObject:nsUuid]; + [uuids addObject:nsUuid]; - // With the latest CoreBluetooth, we can synchronously retrive peripherals: - QT_BT_MAC_AUTORELEASEPOOL; - NSArray *const peripherals = [manager retrievePeripheralsWithIdentifiers:uuids]; - if (!peripherals || peripherals.count != 1) { - qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to retrive a peripheral"; - return QLowEnergyController::UnknownRemoteDeviceError; - } + // With the latest CoreBluetooth, we can synchronously retrive peripherals: + QT_BT_MAC_AUTORELEASEPOOL; + NSArray *const peripherals = [manager retrievePeripheralsWithIdentifiers:uuids]; + if (!peripherals || peripherals.count != 1) { + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to retrive a peripheral"; + return QLowEnergyController::UnknownRemoteDeviceError; + } - peripheral = [static_cast<CBPeripheral *>([peripherals objectAtIndex:0]) retain]; - [self connectToPeripheral]; + peripheral = [static_cast<CBPeripheral *>([peripherals objectAtIndex:0]) retain]; + [self connectToPeripheral]; - return QLowEnergyController::NoError; -#else + return QLowEnergyController::NoError; + } +#endif OSXBluetooth::CFStrongReference<CFUUIDRef> cfUuid(OSXBluetooth::cf_uuid(deviceUuid)); if (!cfUuid) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create CFUUID object"; @@ -243,7 +246,6 @@ using namespace QT_NAMESPACE; [manager retrievePeripherals:uuids]; return QLowEnergyController::NoError; -#endif } - (void)connectToPeripheral @@ -270,10 +272,12 @@ using namespace QT_NAMESPACE; return false; #if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_7_0) - return peripheral.state == CBPeripheralStateConnected; -#else - return peripheral.isConnected; + using OSXBluetooth::qt_OS_limit; + + if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_7_0)) + return peripheral.state == CBPeripheralStateConnected; #endif + return peripheral.isConnected; } - (void)disconnectFromDevice |