OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 Objective C 中将 CBCharacteristic.value 转换为 NSString [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:05
标题: ios - 如何在 Objective C 中将 CBCharacteristic.value 转换为 NSString

我无法将 CBCharacteristic 的 NSData 类型的 value 属性转换为 NSString。我尝试了通常的 initWithData:encoding: NSString 方法,如下所示。但它返回零。

NSString *str = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
NSLog(@"%@", str);

当我直接对值执行 NSLog 时,我可以在控制台上看到字符串值。

NSLog(@"characteristic.value: %@", characteristic.value);

谁能给出关于如何从characteristic.value中获取字符串值的任何想法?



Best Answer-推荐答案


关于ios - 如何在 Objective C 中将 CBCharacteristic.value 转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46923960/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4