0

I am trying to show data in UITextView by appending data coming from peripheral:didUpdateValueForCharacteristic:error:. In this case peripheral:didUpdateValueForCharacteristic:error: is getting called very frequently, due to which UITextView (self.responseTextView) is either unable to print any data or blocks the UI.

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
    if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:UNKNOWN3_CHARACTERISTICS]]) 
   {
        NSData *data = characteristic.value;
        NSString *stringFromData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        self.responseTextView.text = [self.responseTextView.text stringByAppendingString:stringFromData];
        NSLog(@"%@",stringFromData);
    }
}
Larme
  • 24,190
  • 6
  • 51
  • 81
Vineet Ravi
  • 1,457
  • 2
  • 12
  • 26
  • What's the kind of value? Does the value changes? Is it numbers? If it's text, you may only update if the text change, if it's a number, you could wait for 5/10 values (depending) and do an average. You could count the times it's called, and update only if the count is enough high, or maybe use a timestamp and update only if a certain time passed. Or mix all theses ideas... – Larme Oct 22 '15 at 21:30
  • Are you certain that `didUpdateValueForCharacteristic:` is getting called on the main thread? UI updates won't work well from background threads. – picciano Oct 22 '15 at 22:14

0 Answers0