Skip to content

Commit

Permalink
discoverServices crashes in "toDescriptorProto" on iOS #583
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalmaity committed Oct 1, 2021
1 parent 3f9bfdd commit f6382eb
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions ios/Classes/FlutterBluePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,18 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDes
}
ProtosReadDescriptorResponse *result = [[ProtosReadDescriptorResponse alloc] init];
[result setRequest:q];
int value = [descriptor.value intValue];
[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
//int value = [descriptor.value intValue];
//[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
@try {
if ([descriptor.value isKindOfClass:NSNumber.class]) {
int value = [descriptor.value intValue];
[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
} else {
[result setValue:descriptor.value];
}
} @catch (NSException *exception) {
NSLog(exception.reason);
}
[_channel invokeMethod:@"ReadDescriptorResponse" arguments:[self toFlutterData:result]];

// If descriptor is CCCD, send a SetNotificationResponse in case anything is awaiting
Expand Down Expand Up @@ -709,8 +719,18 @@ - (ProtosBluetoothDescriptor*)toDescriptorProto:(CBPeripheral *)peripheral descr
[result setRemoteId:[peripheral.identifier UUIDString]];
[result setCharacteristicUuid:[descriptor.characteristic.UUID fullUUIDString]];
[result setServiceUuid:[descriptor.characteristic.service.UUID fullUUIDString]];
int value = [descriptor.value intValue];
[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
//int value = [descriptor.value intValue];
//[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
@try {
if ([descriptor.value isKindOfClass:NSNumber.class]) {
int value = [descriptor.value intValue];
[result setValue:[NSData dataWithBytes:&value length:sizeof(value)]];
} else {
[result setValue:descriptor.value];
}
} @catch (NSException *exception) {
NSLog(exception.reason);
}
return result;
}

Expand Down

0 comments on commit f6382eb

Please sign in to comment.