diff options
Diffstat (limited to 'src/bluetooth/osx')
-rw-r--r-- | src/bluetooth/osx/osxbtconnectionmonitor.mm | 24 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtconnectionmonitor_p.h | 2 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtutility.mm | 19 | ||||
-rw-r--r-- | src/bluetooth/osx/osxbtutility_p.h | 6 |
4 files changed, 43 insertions, 8 deletions
diff --git a/src/bluetooth/osx/osxbtconnectionmonitor.mm b/src/bluetooth/osx/osxbtconnectionmonitor.mm index b777af8e..f41bbed5 100644 --- a/src/bluetooth/osx/osxbtconnectionmonitor.mm +++ b/src/bluetooth/osx/osxbtconnectionmonitor.mm @@ -81,14 +81,8 @@ using namespace QT_NAMESPACE; - (void)dealloc { - [discoveryNotification unregister]; - [discoveryNotification release]; - - for (IOBluetoothUserNotification *n in foundConnections) - [n unregister]; - - [foundConnections release]; - + Q_ASSERT_X(!monitor, "-dealloc", + "Connection monitor was not stopped, calling -stopMonitoring is required"); [super dealloc]; } @@ -137,4 +131,18 @@ using namespace QT_NAMESPACE; monitor->deviceDisconnected(deviceAddress); } +- (void)stopMonitoring +{ + monitor = nullptr; + [discoveryNotification unregister]; + [discoveryNotification release]; + discoveryNotification = nil; + + for (IOBluetoothUserNotification *n in foundConnections) + [n unregister]; + + [foundConnections release]; + foundConnections = nil; +} + @end diff --git a/src/bluetooth/osx/osxbtconnectionmonitor_p.h b/src/bluetooth/osx/osxbtconnectionmonitor_p.h index 679f6124..50dc9d77 100644 --- a/src/bluetooth/osx/osxbtconnectionmonitor_p.h +++ b/src/bluetooth/osx/osxbtconnectionmonitor_p.h @@ -84,6 +84,8 @@ QT_END_NAMESPACE - (void)connectionNotification:(id)notification withDevice:(IOBluetoothDevice *)device; - (void)connectionClosedNotification:(id)notification withDevice:(IOBluetoothDevice *)device; +- (void)stopMonitoring; + @end #endif diff --git a/src/bluetooth/osx/osxbtutility.mm b/src/bluetooth/osx/osxbtutility.mm index c7fa7c42..3d41a224 100644 --- a/src/bluetooth/osx/osxbtutility.mm +++ b/src/bluetooth/osx/osxbtutility.mm @@ -42,6 +42,7 @@ #include "osxbtutility_p.h" #include "qbluetoothuuid.h" +#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qendian.h> #include <QtCore/qstring.h> @@ -76,6 +77,8 @@ const int defaultLEScanTimeoutMS = 25000; // We use it only on iOS for now: const int maxValueLength = 512; +NSString *const bluetoothUsageKey = @"NSBluetoothAlwaysUsageDescription"; + QString qt_address(NSString *address) { if (address && address.length) { @@ -351,6 +354,22 @@ ObjCStrongReference<NSMutableData> mutable_data_from_bytearray(const QByteArray return result; } +bool qt_appNeedsBluetoothUsageDescription() +{ +#ifdef Q_OS_MACOS + return QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSBigSur; +#endif + return true; +} + +bool qt_appPlistContainsDescription(NSString *key) +{ + Q_ASSERT(key); + + NSDictionary<NSString *, id> *infoDict = NSBundle.mainBundle.infoDictionary; + return !!infoDict[key]; +} + // A small RAII class for a dispatch queue. class SerialDispatchQueue { diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h index c2bc6cf8..1b1d44be 100644 --- a/src/bluetooth/osx/osxbtutility_p.h +++ b/src/bluetooth/osx/osxbtutility_p.h @@ -307,6 +307,12 @@ dispatch_queue_t qt_LE_queue(); extern const int defaultLEScanTimeoutMS; extern const int maxValueLength; +// Add more keys if needed, for now this one is enough: +extern NSString *const bluetoothUsageKey; + +bool qt_appNeedsBluetoothUsageDescription(); +bool qt_appPlistContainsDescription(NSString *key); + } // namespace OSXBluetooth // Logging category for both OS X and iOS. |