iOS Obj-C How to parse and use a buffer for incoming BTLE bytes for UIText display?

I'm receiving data successfully in the BLE app I've built for iPhone/iPad however, converting the bytes to a single NSString for a UILabel display has proven challenging at best.

With an input of "123456789" the bytes get broken in to 4 separate messages.

This is the didUpdateValueForCharacteristic method I'm using for testing:

NSString *myStr = [[NSString alloc] initWithData:characteristic.value encoding:NSASCIIStringEncoding];

 [self.dataBuffer appendData:characteristic.value];
 [self.textView setText:[[NSString alloc] initWithData:self.dataBuffer encoding:NSASCIIStringEncoding]];

 //NSUInteger bytes = [self.dataBuffer length];
 NSLog(@"Data: %@", myStr);

Xcode Log:

2014-03-10 22:53:27.771 BTLE-Sensor[2860:60b] Data: 1
2014-03-10 22:53:27.775 BTLE-Sensor[2860:60b] Data: 2345
2014-03-10 22:53:27.777 BTLE-Sensor[2860:60b] Data: 678
2014-03-10 22:53:27.779 BTLE-Sensor[2860:60b] Data: 9

And the label of course displays only the last received byte: 9

Obviously I'd like to have the UILabel display: 123456789

I've tried appendData functions and more "for" loop iterations than I'd like to remember!



You're not really appending the string, you're creating and setting it every time as your textView's text. Do this:

 [self.textView setText:[self.textView.text stringByAppendingString:[[NSString alloc] initWithData:self.dataBuffer encoding:NSASCIIStringEncoding]]];

Need Your Help

About interrupt context,atomic context and process context in linux kernel

linux linux-kernel interrupt

As I know, we can verify that we are in interrupt context by involving in_interrupt() in linux kernel. And the implementation of the in_interrupt() function is counting by the thread_info->

How to animate specific corners of the border radius when hovered in and out? (Firefox)

jquery animation border css3

I know how to do this for Webkit browsers but I'm kinda stuck in Firefox. The code below just animate the top-left corner while the rest just snap into places.