diff options
author | Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> | 2015-10-01 10:33:42 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> | 2015-10-12 13:54:50 +0000 |
commit | cf8b244f94fdabf5c960d82c4bbcbf13c91c29b1 (patch) | |
tree | 1a52d763ccdad7b22bafdba79f12e2de238455c0 | |
parent | 59bc397f0ac0e0c333c415f25782f2a6614fc03a (diff) |
CoreBluetooth - update for iOS 9.0
New SDK removed deprecated properties/methods and we have a compilation error
as a result.
Use performSelector instead of direct calls to make sure:
1. it compiles
2. it calls an existing method.
This is a backport of 371818e71839280abafae858e9bb53c4ee6b9e5e.
Task-number:QTBUG-48518
Change-Id: I10a2d062f9e71229a1e218d9d167a4132b97b6ab
Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/bluetooth/osx/osxbtcentralmanager.mm | 19 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtledeviceinquiry.mm | 22 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm index 08905da8..614e4ae5 100644 --- a/src/bluetooth/osx/osxbtcentralmanager.mm +++ b/src/bluetooth/osx/osxbtcentralmanager.mm @@ -201,8 +201,8 @@ using namespace QT_NAMESPACE; return QLowEnergyController::ConnectionError; } -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_6_0)) { +#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_7_0) + if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_7_0)) { const quint128 qtUuidData(deviceUuid.toUInt128()); // STATIC_ASSERT on sizes would be handy! uuid_t uuidData = {}; @@ -229,6 +229,12 @@ using namespace QT_NAMESPACE; return QLowEnergyController::NoError; } #endif + // Either SDK or the target is below 10.9/7.0 + if (![manager respondsToSelector:@selector(retrievePeripherals:)]) { + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to retrive a peripheral"; + return QLowEnergyController::UnknownRemoteDeviceError; + } + OSXBluetooth::CFStrongReference<CFUUIDRef> cfUuid(OSXBluetooth::cf_uuid(deviceUuid)); if (!cfUuid) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create CFUUID object"; @@ -238,7 +244,7 @@ using namespace QT_NAMESPACE; [uuids addObject:(id)cfUuid.data()]; // Unfortunately, with old Core Bluetooth this call is asynchronous ... managerState = OSXBluetooth::CentralManagerConnecting; - [manager retrievePeripherals:uuids]; + [manager performSelector:@selector(retrievePeripherals:) withObject:uuids.data()]; return QLowEnergyController::NoError; } @@ -272,7 +278,12 @@ using namespace QT_NAMESPACE; if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_7_0)) return peripheral.state == CBPeripheralStateConnected; #endif - return peripheral.isConnected; + // Either SDK or the target is below 10.9/7.0 ... + if (![peripheral respondsToSelector:@selector(isConnected)]) + return false; + + // Ugly cast to deal with id being a pointer ... + return reinterpret_cast<quintptr>([peripheral performSelector:@selector(isConnected)]); } - (void)disconnectFromDevice diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index af304d8d..c46c68fc 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -295,8 +295,8 @@ using namespace QT_NAMESPACE; Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)"); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_6_0) - if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_6_0)) { +#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_7_0) + if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_9, QSysInfo::MV_IOS_7_0)) { if (!peripheral.identifier) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "peripheral without NSUUID"; return; @@ -310,15 +310,25 @@ using namespace QT_NAMESPACE; return; } #endif - if (!peripheral.UUID) { - qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "peripheral without UUID"; + // Either SDK or the target is below 10.9/7.0: + // The property UUID was finally removed in iOS 9, we have + // to avoid compilation errors ... + CFUUIDRef cfUUID = Q_NULLPTR; + + if ([peripheral respondsToSelector:@selector(UUID)]) { + // This will require a bridged cast if we switch to ARC ... + cfUUID = reinterpret_cast<CFUUIDRef>([peripheral performSelector:@selector(UUID)]); + } + + if (!cfUUID) { + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "peripheral without CFUUID"; return; } - StringStrongReference key(uuid_as_nsstring(peripheral.UUID)); + StringStrongReference key(uuid_as_nsstring(cfUUID)); if (![peripherals objectForKey:key.data()]) { [peripherals setObject:peripheral forKey:key.data()]; - const QBluetoothUuid deviceUuid(OSXBluetooth::qt_uuid(peripheral.UUID)); + const QBluetoothUuid deviceUuid(OSXBluetooth::qt_uuid(cfUUID)); delegate->LEdeviceFound(peripheral, deviceUuid, advertisementData, RSSI); } } |