Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, any Error>) -> Void) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
universal_ble: d0c3d7347d16c82746288e13ed2f1368ecf8e716
universal_ble: a322ebabee64f0ec27a313e89a5dd6967f37a60f

PODFILE CHECKSUM: 54d867c82ac51cbd61b565781b9fada492027009

Expand Down