diff --git a/darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift b/darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift index 10f8c871..3082546f 100644 --- a/darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift +++ b/darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift @@ -55,11 +55,15 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral }() private static var hasBluetoothPermission: Bool { - CBCentralManager.authorization == .allowedAlways + if #available(iOS 13.1, *) { + return CBCentralManager.authorization == .allowedAlways + } + return false } /// Availability derived from `CBCentralManager.authorization` without creating a manager. private static var availabilityStateFromAuthorization: AvailabilityState { + guard #available(iOS 13.1, *) else { return .unknown } switch CBCentralManager.authorization { case .restricted, .denied: return .unauthorized @@ -107,6 +111,13 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral super.init() } + private func isBluetoothAuthorized() -> Bool { + if #available(iOS 13.1, macOS 10.15, *) { + return CBCentralManager.authorization == .allowedAlways + } + return false + } + #if os(iOS) /// Eagerly creates the central manager at launch when the app declares the /// `bluetooth-central` background mode and Bluetooth permission is already @@ -135,7 +146,7 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral } func hasPermissions(withAndroidFineLocation _: Bool) throws -> Bool { - return CBCentralManager.authorization == .allowedAlways + return isBluetoothAuthorized() } func requestPermissions(withAndroidFineLocation _: Bool, completion: @escaping (Result) -> Void) { @@ -196,7 +207,7 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral } func isScanning() throws -> Bool { - if CBCentralManager.authorization == .allowedAlways { + if isBluetoothAuthorized() { return manager.isScanning } return isManageScanning diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 7eeecf30..66748eaa 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -16,7 +16,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1 - universal_ble: d0c3d7347d16c82746288e13ed2f1368ecf8e716 + universal_ble: a322ebabee64f0ec27a313e89a5dd6967f37a60f PODFILE CHECKSUM: 54d867c82ac51cbd61b565781b9fada492027009