@@ -3666,23 +3666,32 @@ -(NSMutableDictionary*) getProperties:(CBCharacteristic*) characteristic {
36663666
36673667- (void )writeDataToCharacteristic : (CBCharacteristic *)characteristic toPeripheral : (CBPeripheral*) peripheral {
36683668 NSData *data;
3669- if (self->writeQLocation + self->writeQChunkSize > self->writeQLength ) {
3670- NSInteger currentLength = self->writeQLength - self->writeQLocation ;
3671- NSMutableData *mutableData = [[NSMutableData alloc ] initWithData: [self ->writeQData subdataWithRange: NSMakeRange (self ->writeQLocation, currentLength)]];
3672- data = [[NSData alloc ] initWithData: mutableData];
3673- self->writeQLocation = self->writeQLocation + currentLength;
3674- } else {
3675- data = [self ->writeQData subdataWithRange: NSMakeRange (self ->writeQLocation, self ->writeQChunkSize)];
3676- self->writeQLocation = self->writeQLocation + self->writeQChunkSize ;
3677- }
36783669
3679- // Since WriteWithoutResponse triggers a different callback which has no access to characteristic
36803670 if (self->writeQtype == CBCharacteristicWriteWithoutResponse) {
3671+ // Since WriteWithoutResponse triggers a different callback which has no access to characteristic
36813672 self->currentWriteCharacteristic = characteristic;
3682- }
36833673
3684- if (peripheral.canSendWriteWithoutResponse ) {
3685- [peripheral writeValue: data forCharacteristic: characteristic type: self ->writeQtype];
3674+ while (self->writeQLocation < self->writeQLength && peripheral.canSendWriteWithoutResponse ) {
3675+ NSInteger currentLength = self->writeQLength - self->writeQLocation ;
3676+ NSInteger chunkSize = currentLength < self->writeQChunkSize ? currentLength : self->writeQChunkSize ;
3677+
3678+ data = [self ->writeQData subdataWithRange: NSMakeRange (self ->writeQLocation, chunkSize)];
3679+
3680+ [peripheral writeValue: data forCharacteristic: characteristic type: self ->writeQtype];
3681+
3682+ self->writeQLocation = self->writeQLocation + chunkSize;
3683+ }
3684+ } else {
3685+ while (self->writeQLocation < self->writeQLength ) {
3686+ NSInteger currentLength = self->writeQLength - self->writeQLocation ;
3687+ NSInteger chunkSize = currentLength < self->writeQChunkSize ? currentLength : self->writeQChunkSize ;
3688+
3689+ data = [self ->writeQData subdataWithRange: NSMakeRange (self ->writeQLocation, chunkSize)];
3690+
3691+ [peripheral writeValue: data forCharacteristic: characteristic type: self ->writeQtype];
3692+
3693+ self->writeQLocation = self->writeQLocation + chunkSize;
3694+ }
36863695 }
36873696}
36883697
0 commit comments