使用LightBlueApplication在BLE上读取NSdata

时间:2013-11-19 07:20:14

标签: ios nsdata core-bluetooth cbperipheral cbcentralmanager

我正在尝试读取我存储在lightBlue应用程序中的值,但问题是它似乎无法获取字符串。它检测到我正在读取数据,但是当我将数据转换为字符串时,它会输出@“”

 -(void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
   if([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"2A29"]]){
     if (characteristic.value) {
         NSString *stringFromData = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
        NSLog(@"The String is %@", stringFromData);
        self.manufacturer = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
        NSLog(@"Manufacturer Name = %@", self.manufacturer);
     }
   }

}

1 个答案:

答案 0 :(得分:0)

尝试使用此代码 NSString *stringFromData = [[NSString alloc] initWithData:characteristic.value encoding:NSASCIIStringEncoding]; NSLog(@"The String is %@", stringFromData);