diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2021-05-06 17:23:42 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2021-05-11 11:05:09 +0200 |
commit | bc3352eb40e8601d8be2909cc96363b3b41ce0a0 (patch) | |
tree | a963b7dd614f49dad0e33e756d742436b5c4d637 | |
parent | 6d5e8dfafff7fc4ef9269bacd692fb6d93b2bc1f (diff) |
CoreBluetooth: add a workaround to enable using scan options
By default, the value for CBCentralManagerScanOptionAllowDuplicatesKey
is 'NO' (but either passing it explicitly or passing nil as 'otpions').
According to a report, this disables a proper device discovery (contrary
to what is documented by Apple). Since, according to the Apple's docs,
"Disabling this filtering can have an adverse effect on battery life;
use it only if necessary", we don't set it by default and instead
provide a workaround using environment variable to set the option,
if needed. The name of this variable is:
"QT_BLUETOOTH_SCAN_ENABLE_DUPLICATES".
[ChangeLog][QtConnecivity][Bluetooth][Darwin] Enable setting a scan option (that allows duplicates)
Change-Id: I08a5a089020c433a87bcb622d08aa2cd260283b9
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
(cherry picked from commit e0e46f3f4cd5f482ef8a95b87a3d341cc3bf4076)
-rw-r--r-- | src/bluetooth/osx/osxbtledeviceinquiry.mm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm index 8ed1ebc7..3a3bb4b4 100644 --- a/src/bluetooth/osx/osxbtledeviceinquiry.mm +++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm @@ -218,7 +218,15 @@ QT_USE_NAMESPACE [elapsedTimer startWithTimeout:inquiryTimeoutMS step:timeStepMS]; } - [manager scanForPeripheralsWithServices:nil options:nil]; + // ### Qt 6.x: remove the use of env. variable, as soon as a proper public API is in place. + bool envOk = false; + const int env = qEnvironmentVariableIntValue("QT_BLUETOOTH_SCAN_ENABLE_DUPLICATES", &envOk); + if (envOk && env) { + [manager scanForPeripheralsWithServices:nil + options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @YES}]; + } else { + [manager scanForPeripheralsWithServices:nil options:nil]; + } } // Else we ignore. #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13) } else if (state == CBManagerStateUnsupported || state == CBManagerStateUnauthorized) { |