Implement hasPermissions API (#201)
* Implement hasPermissions api * Bump minimum MacOS version to 10.15 * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -529,6 +529,7 @@ class UniversalBlePigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable
|
||||
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
|
||||
protocol UniversalBlePlatformChannel {
|
||||
func getBluetoothAvailabilityState(completion: @escaping (Result<Int64, Error>) -> Void)
|
||||
func hasPermissions(withAndroidFineLocation: Bool) throws -> Bool
|
||||
func requestPermissions(withAndroidFineLocation: Bool, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func enableBluetooth(completion: @escaping (Result<Bool, Error>) -> Void)
|
||||
func disableBluetooth(completion: @escaping (Result<Bool, Error>) -> Void)
|
||||
@@ -571,6 +572,21 @@ class UniversalBlePlatformChannelSetup {
|
||||
} else {
|
||||
getBluetoothAvailabilityStateChannel.setMessageHandler(nil)
|
||||
}
|
||||
let hasPermissionsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.hasPermissions\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
hasPermissionsChannel.setMessageHandler { message, reply in
|
||||
let args = message as! [Any?]
|
||||
let withAndroidFineLocationArg = args[0] as! Bool
|
||||
do {
|
||||
let result = try api.hasPermissions(withAndroidFineLocation: withAndroidFineLocationArg)
|
||||
reply(wrapResult(result))
|
||||
} catch {
|
||||
reply(wrapError(error))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hasPermissionsChannel.setMessageHandler(nil)
|
||||
}
|
||||
let requestPermissionsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestPermissions\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
requestPermissionsChannel.setMessageHandler { message, reply in
|
||||
|
||||
@@ -56,6 +56,10 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
||||
}
|
||||
}
|
||||
|
||||
func hasPermissions(withAndroidFineLocation _: Bool) throws -> Bool {
|
||||
return CBCentralManager.authorization == .allowedAlways
|
||||
}
|
||||
|
||||
func requestPermissions(withAndroidFineLocation _: Bool, completion: @escaping (Result<Void, any Error>) -> Void) {
|
||||
if manager.state != .unknown {
|
||||
completePermissionRequest(completion: completion)
|
||||
@@ -114,21 +118,9 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral
|
||||
}
|
||||
|
||||
func isScanning() throws -> Bool {
|
||||
var hasAuthorization = true
|
||||
#if os(iOS)
|
||||
if #available(iOS 13.1, *) {
|
||||
hasAuthorization = CBCentralManager.authorization == .allowedAlways
|
||||
} else {
|
||||
return isManageScanning
|
||||
}
|
||||
#elseif os(macOS)
|
||||
hasAuthorization = CBCentralManager.authorization == .allowedAlways
|
||||
#endif
|
||||
|
||||
if hasAuthorization {
|
||||
if CBCentralManager.authorization == .allowedAlways {
|
||||
return manager.isScanning
|
||||
}
|
||||
|
||||
return isManageScanning
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ A new Flutter plugin project.
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.ios.dependency 'Flutter'
|
||||
s.osx.dependency 'FlutterMacOS'
|
||||
s.ios.deployment_target = '9.0'
|
||||
s.osx.deployment_target = '10.12'
|
||||
s.ios.deployment_target = '13.1'
|
||||
s.osx.deployment_target = '10.15'
|
||||
|
||||
# Flutter.framework does not contain a i386 slice.
|
||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
|
||||
|
||||
Reference in New Issue
Block a user