Skip to content

Commit 0f3ba43

Browse files
pauldemarcoPaul DeMarco
authored and
Paul DeMarco
committed
Fixed char/descriptor protos on iOS.
1 parent 09dd5a9 commit 0f3ba43

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

ios/Classes/FlutterBluePlugin.m

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(C
425425
NSLog(@"didUpdateValueForCharacteristic %@", [peripheral.identifier UUIDString]);
426426
ProtosReadCharacteristicResponse *result = [[ProtosReadCharacteristicResponse alloc] init];
427427
[result setRemoteId:[peripheral.identifier UUIDString]];
428-
[result setCharacteristic:[self toCharacteristicProto:characteristic]];
428+
[result setCharacteristic:[self toCharacteristicProto:peripheral characteristic:characteristic]];
429429
[_channel invokeMethod:@"ReadCharacteristicResponse" arguments:[self toFlutterData:result]];
430430

431431
// on iOS, this method also handles notification values
432-
ProtosOnCharacteristicChanged *result = [[ProtosOnCharacteristicChanged alloc] init];
433-
[result setRemoteId:[peripheral.identifier UUIDString]];
434-
[result setCharacteristic:[self toCharacteristicProto:characteristic]];
435-
[_channel invokeMethod:@"OnCharacteristicChanged" arguments:[self toFlutterData:result]];
432+
ProtosOnCharacteristicChanged *onChangedResult = [[ProtosOnCharacteristicChanged alloc] init];
433+
[onChangedResult setRemoteId:[peripheral.identifier UUIDString]];
434+
[onChangedResult setCharacteristic:[self toCharacteristicProto:peripheral characteristic:characteristic]];
435+
[_channel invokeMethod:@"OnCharacteristicChanged" arguments:[self toFlutterData:onChangedResult]];
436436
}
437437

438438
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
@@ -455,7 +455,7 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForChara
455455
// Send error
456456
ProtosSetNotificationResponse *response = [[ProtosSetNotificationResponse alloc] init];
457457
[response setRemoteId:[peripheral.identifier UUIDString]];
458-
[response setCharacteristic:[self toCharacteristicProto:characteristic]];
458+
[response setCharacteristic:[self toCharacteristicProto:peripheral characteristic:characteristic]];
459459
[response setSuccess:false];
460460
[_channel invokeMethod:@"SetNotificationResponse" arguments:[self toFlutterData:response]];
461461
return;
@@ -487,7 +487,7 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDes
487487
if([descriptor.UUID.UUIDString isEqualToString:@"2902"]){
488488
ProtosSetNotificationResponse *response = [[ProtosSetNotificationResponse alloc] init];
489489
[response setRemoteId:[peripheral.identifier UUIDString]];
490-
[response setCharacteristic:[self toCharacteristicProto:descriptor.characteristic]];
490+
[response setCharacteristic:[self toCharacteristicProto:peripheral characteristic:descriptor.characteristic]];
491491
[response setSuccess:true];
492492
[_channel invokeMethod:@"SetNotificationResponse" arguments:[self toFlutterData:response]];
493493
}
@@ -629,7 +629,7 @@ - (ProtosBluetoothService*)toServiceProto:(CBPeripheral *)peripheral service:(CB
629629
// Characteristic Array
630630
NSMutableArray *characteristicProtos = [NSMutableArray new];
631631
for(CBCharacteristic *c in [service characteristics]) {
632-
[characteristicProtos addObject:[self toCharacteristicProto:c]];
632+
[characteristicProtos addObject:[self toCharacteristicProto:peripheral characteristic:c]];
633633
}
634634
[result setCharacteristicsArray:characteristicProtos];
635635

@@ -643,15 +643,16 @@ - (ProtosBluetoothService*)toServiceProto:(CBPeripheral *)peripheral service:(CB
643643
return result;
644644
}
645645

646-
- (ProtosBluetoothCharacteristic*)toCharacteristicProto:(CBCharacteristic *)characteristic {
646+
- (ProtosBluetoothCharacteristic*)toCharacteristicProto:(CBPeripheral *)peripheral characteristic:(CBCharacteristic *)characteristic {
647647
ProtosBluetoothCharacteristic *result = [[ProtosBluetoothCharacteristic alloc] init];
648648
[result setUuid:[characteristic.UUID fullUUIDString]];
649+
[result setRemoteId:[peripheral.identifier UUIDString]];
649650
[result setProperties:[self toCharacteristicPropsProto:characteristic.properties]];
650651
[result setValue:[characteristic value]];
651652
NSLog(@"uuid: %@ value: %@", [characteristic.UUID fullUUIDString], [characteristic value]);
652653
NSMutableArray *descriptorProtos = [NSMutableArray new];
653654
for(CBDescriptor *d in [characteristic descriptors]) {
654-
[descriptorProtos addObject:[self toDescriptorProto:d]];
655+
[descriptorProtos addObject:[self toDescriptorProto:peripheral descriptor:d]];
655656
}
656657
[result setDescriptorsArray:descriptorProtos];
657658
if([characteristic.service isPrimary]) {
@@ -665,9 +666,10 @@ - (ProtosBluetoothCharacteristic*)toCharacteristicProto:(CBCharacteristic *)char
665666
return result;
666667
}
667668

668-
- (ProtosBluetoothDescriptor*)toDescriptorProto:(CBDescriptor *)descriptor {
669+
- (ProtosBluetoothDescriptor*)toDescriptorProto:(CBPeripheral *)peripheral descriptor:(CBDescriptor *)descriptor {
669670
ProtosBluetoothDescriptor *result = [[ProtosBluetoothDescriptor alloc] init];
670671
[result setUuid:[descriptor.UUID fullUUIDString]];
672+
[result setRemoteId:[peripheral.identifier UUIDString]];
671673
[result setCharacteristicUuid:[descriptor.characteristic.UUID fullUUIDString]];
672674
[result setServiceUuid:[descriptor.characteristic.service.UUID fullUUIDString]];
673675
int value = [descriptor.value intValue];

0 commit comments

Comments
 (0)