Question

I am working with iOS central to communicate with BLE peripheral device.

Using LGBluetooth framework https://github.com/DavidSahakyan/LGBluetooth

The method gets

        [LGUtils readDataFromCharactUUID:aCharactId
                              seriveUUID:aServiceId
                              peripheral:peripheral
                              completion:^(NSData *data, NSError *error) {
                                  NSLog(@"Data : %s Error : %@", (char *)[data bytes], error);
                              }];

It outputs "1234567890"

I need to convert (char *) [data bytes] to NSInteger. When I get it

         NSInteger dataInt = [data bytes];

I get 2013527536, but the value is 1234567890 on peripheral side

Was it helpful?

Solution

Try to do something like that:

NSInteger dataInt = atoi((const char*)[data bytes]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top