修复 CoW 代码问题 (#40)
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 5.0.4
|
||||
|
||||
* `iOS` Fix issues caused by CoW.
|
||||
|
||||
## 5.0.3
|
||||
|
||||
* `Android` Fix the wrong blutooth low energy state caused by multi permission requests at the same time.
|
||||
|
@ -979,9 +979,21 @@ class _AdvertiserViewState extends State<AdvertiserView>
|
||||
|
||||
Future<void> startAdvertising() async {
|
||||
await PeripheralManager.instance.clearServices();
|
||||
final batteryService = GattService(
|
||||
uuid: UUID.short(0x180f),
|
||||
characteristics: [
|
||||
GattCharacteristic(
|
||||
uuid: UUID.short(0x2A19),
|
||||
properties: [GattCharacteristicProperty.read],
|
||||
value: Uint8List.fromList([75]),
|
||||
descriptors: [],
|
||||
),
|
||||
],
|
||||
);
|
||||
await PeripheralManager.instance.addService(batteryService);
|
||||
final elements = List.generate(1000, (i) => i % 256);
|
||||
final value = Uint8List.fromList(elements);
|
||||
final service = GattService(
|
||||
final myService = GattService(
|
||||
uuid: UUID.short(100),
|
||||
characteristics: [
|
||||
GattCharacteristic(
|
||||
@ -1028,19 +1040,7 @@ class _AdvertiserViewState extends State<AdvertiserView>
|
||||
),
|
||||
],
|
||||
);
|
||||
await PeripheralManager.instance.addService(service);
|
||||
final batteryService = GattService(
|
||||
uuid: UUID.short(0x180f),
|
||||
characteristics: [
|
||||
GattCharacteristic(
|
||||
uuid: UUID.short(0x2A19),
|
||||
properties: [GattCharacteristicProperty.read],
|
||||
value: Uint8List.fromList([75]),
|
||||
descriptors: [],
|
||||
),
|
||||
],
|
||||
);
|
||||
await PeripheralManager.instance.addService(batteryService);
|
||||
await PeripheralManager.instance.addService(myService);
|
||||
final advertisement = Advertisement(
|
||||
name: 'le12138',
|
||||
manufacturerSpecificData: ManufacturerSpecificData(
|
||||
|
@ -23,7 +23,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "5.0.3"
|
||||
version: "5.0.4"
|
||||
bluetooth_low_energy_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -36,10 +36,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: bluetooth_low_energy_darwin
|
||||
sha256: "876fd1c7eadd5e4eea92257dd3d2ec31f3c0bb68f8e96c564ed28ecde7382bd1"
|
||||
sha256: e85bc6e97a087f2bb934a1b12953a0f6aab8dfdbe57302cb2bf6d61b996fa2ee
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.2"
|
||||
version: "5.0.3"
|
||||
bluetooth_low_energy_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: bluetooth_low_energy
|
||||
description: A Flutter plugin for controlling the bluetooth low energy, supports central and peripheral apis.
|
||||
version: 5.0.3
|
||||
version: 5.0.4
|
||||
homepage: https://github.com/yanshouwang/bluetooth_low_energy
|
||||
|
||||
environment:
|
||||
@ -12,7 +12,7 @@ dependencies:
|
||||
sdk: flutter
|
||||
bluetooth_low_energy_platform_interface: ^5.0.0
|
||||
bluetooth_low_energy_android: ^5.0.2
|
||||
bluetooth_low_energy_darwin: ^5.0.2
|
||||
bluetooth_low_energy_darwin: ^5.0.3
|
||||
bluetooth_low_energy_windows: ^5.0.0
|
||||
bluetooth_low_energy_linux: ^5.0.0
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
## 5.0.3
|
||||
|
||||
* Fix issues caused by CoW.
|
||||
|
||||
## 5.0.2
|
||||
|
||||
* Fix the issue that [discoverGATT failed caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36).
|
||||
|
@ -67,7 +67,7 @@ class MyCentralManager: MyCentralManagerHostApi {
|
||||
if _centralManager.delegate == nil {
|
||||
_centralManager.delegate = _centralManagerDelegate
|
||||
}
|
||||
_onStateChanged()
|
||||
didUpdateState(central: _centralManager)
|
||||
}
|
||||
|
||||
func startDiscovery() throws {
|
||||
@ -259,7 +259,10 @@ class MyCentralManager: MyCentralManagerHostApi {
|
||||
}
|
||||
|
||||
func didUpdateState(central: CBCentralManager) {
|
||||
_onStateChanged()
|
||||
let state = central.state
|
||||
let stateArgs = state.toArgs()
|
||||
let stateNumberArgs = stateArgs.rawValue.toInt64()
|
||||
_api.onStateChanged(stateNumberArgs: stateNumberArgs) {_ in }
|
||||
}
|
||||
|
||||
func didDiscover(central: CBCentralManager, peripheral: CBPeripheral, advertisementData: [String : Any], rssi: NSNumber) {
|
||||
@ -588,11 +591,4 @@ class MyCentralManager: MyCentralManagerHostApi {
|
||||
}
|
||||
return descriptors[hashCodeArgs]
|
||||
}
|
||||
|
||||
private func _onStateChanged() {
|
||||
let state = _centralManager.state
|
||||
let stateArgs = state.toArgs()
|
||||
let stateNumberArgs = stateArgs.rawValue.toInt64()
|
||||
_api.onStateChanged(stateNumberArgs: stateNumberArgs) {_ in }
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class MyPeripheralManager: MyPeripheralManagerHostApi {
|
||||
if _peripheralManager.delegate == nil {
|
||||
_peripheralManager.delegate = _peripheralManagerDelegate
|
||||
}
|
||||
_onStateChanged()
|
||||
didUpdateState(peripheral: _peripheralManager)
|
||||
}
|
||||
|
||||
func addService(serviceArgs: MyGattServiceArgs, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@ -102,23 +102,48 @@ class MyPeripheralManager: MyPeripheralManagerHostApi {
|
||||
}
|
||||
|
||||
func removeService(hashCodeArgs: Int64) throws {
|
||||
guard let service = _services[hashCodeArgs] else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
let hashCode = service.hash
|
||||
guard let serviceArgs = _servicesArgs[hashCode] else {
|
||||
guard let service = _services.removeValue(forKey: hashCodeArgs) else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
_peripheralManager.remove(service)
|
||||
_clearService(serviceArgs: serviceArgs)
|
||||
let hashCode = service.hash
|
||||
guard let serviceArgs = _servicesArgs.removeValue(forKey: hashCode) else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
for args in serviceArgs.characteristicsArgs {
|
||||
guard let characteristicArgs = args else {
|
||||
continue
|
||||
}
|
||||
let characteristicHashCodeArgs = characteristicArgs.hashCodeArgs
|
||||
guard let characteristic = _characteristics.removeValue(forKey: characteristicHashCodeArgs) else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
let characteristicHashCode = characteristic.hash
|
||||
_characteristicsArgs.removeValue(forKey: characteristicHashCode)
|
||||
for args in characteristicArgs.descriptorsArgs {
|
||||
guard let descriptorArgs = args else {
|
||||
continue
|
||||
}
|
||||
let descriptorHashCodeArgs = descriptorArgs.hashCodeArgs
|
||||
guard let descriptor = _descriptors.removeValue(forKey: descriptorHashCodeArgs) else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
let descriptorHashCode = descriptor.hash
|
||||
_descriptorsArgs.removeValue(forKey: descriptorHashCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func clearServices() throws {
|
||||
_peripheralManager.removeAllServices()
|
||||
let servicesArgs = _servicesArgs.values
|
||||
for serviceArgs in servicesArgs {
|
||||
_clearService(serviceArgs: serviceArgs)
|
||||
}
|
||||
|
||||
_services.removeAll()
|
||||
_characteristics.removeAll()
|
||||
_descriptors.removeAll()
|
||||
|
||||
_servicesArgs.removeAll()
|
||||
_characteristicsArgs.removeAll()
|
||||
_descriptors.removeAll()
|
||||
}
|
||||
|
||||
func startAdvertising(advertisementArgs: MyAdvertisementArgs, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@ -181,7 +206,10 @@ class MyPeripheralManager: MyPeripheralManagerHostApi {
|
||||
}
|
||||
|
||||
func didUpdateState(peripheral: CBPeripheralManager) {
|
||||
_onStateChanged()
|
||||
let state = peripheral.state
|
||||
let stateArgs = state.toArgs()
|
||||
let stateNumberArgs = stateArgs.rawValue.toInt64()
|
||||
_api.onStateChanged(stateNumberArgs: stateNumberArgs) {_ in }
|
||||
}
|
||||
|
||||
func didAdd(peripheral: CBPeripheralManager, service: CBService, error: Error?) {
|
||||
@ -193,11 +221,6 @@ class MyPeripheralManager: MyPeripheralManagerHostApi {
|
||||
completion(.success(()))
|
||||
} else {
|
||||
completion(.failure(error!))
|
||||
let hashCode = service.hash
|
||||
guard let serviceArgs = _servicesArgs[hashCode] else {
|
||||
return
|
||||
}
|
||||
_clearService(serviceArgs: serviceArgs)
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,44 +340,4 @@ class MyPeripheralManager: MyPeripheralManagerHostApi {
|
||||
_startAdvertisingCompletion = nil
|
||||
_isReadyToUpdateSubscribersCallbacks.removeAll()
|
||||
}
|
||||
|
||||
private func _clearService(serviceArgs: MyGattServiceArgs) {
|
||||
let characteristicsArgs = serviceArgs.characteristicsArgs
|
||||
for args in characteristicsArgs {
|
||||
guard let characteristicArgs = args else {
|
||||
continue
|
||||
}
|
||||
let descriptorsArgs = characteristicArgs.descriptorsArgs
|
||||
for args in descriptorsArgs {
|
||||
guard let descriptorArgs = args else {
|
||||
continue
|
||||
}
|
||||
let descriptorHashCodeArgs = descriptorArgs.hashCodeArgs
|
||||
guard let descriptor = _descriptors.removeValue(forKey: descriptorHashCodeArgs) else {
|
||||
continue
|
||||
}
|
||||
let descriptorHashCode = descriptor.hash
|
||||
_descriptorsArgs.removeValue(forKey: descriptorHashCode)
|
||||
}
|
||||
let characteristicHashCodeArgs = characteristicArgs.hashCodeArgs
|
||||
guard let characteristic = _characteristics.removeValue(forKey: characteristicHashCodeArgs) else {
|
||||
continue
|
||||
}
|
||||
let characteristicHashCode = characteristic.hash
|
||||
_characteristicsArgs.removeValue(forKey: characteristicHashCode)
|
||||
}
|
||||
let serviceHashCodeArgs = serviceArgs.hashCodeArgs
|
||||
guard let service = _services.removeValue(forKey: serviceHashCodeArgs) else {
|
||||
return
|
||||
}
|
||||
let serviceHashCode = service.hash
|
||||
_servicesArgs.removeValue(forKey: serviceHashCode)
|
||||
}
|
||||
|
||||
private func _onStateChanged() {
|
||||
let state = _peripheralManager.state
|
||||
let stateArgs = state.toArgs()
|
||||
let stateNumberArgs = stateArgs.rawValue.toInt64()
|
||||
_api.onStateChanged(stateNumberArgs: stateNumberArgs) {_ in }
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "5.0.2"
|
||||
version: "5.0.3"
|
||||
bluetooth_low_energy_platform_interface:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: bluetooth_low_energy_darwin
|
||||
description: iOS and macOS implementation of the bluetooth_low_energy plugin.
|
||||
version: 5.0.2
|
||||
version: 5.0.3
|
||||
homepage: https://github.com/yanshouwang/bluetooth_low_energy
|
||||
|
||||
environment:
|
||||
|
Reference in New Issue
Block a user