ios - Corebluetooth 读取特性值变化

标签 ios swift core-bluetooth

我目前正在将我的项目从 swift 2.3 迁移到 swift 3,我对一件事感到困惑。在 swift 2.3 中,我可以简单地使用

 print("value \(characteristic.value!)")

它会打印我收到的值 61。但是在 swift 3 中它会打印 1 个字节。为了获得我尝试使用命令的值

print("value \(characteristic.properties.rawvalue)")

使用此命令,它会返回值。但苹果为什么要改变这一点?

编辑

不知道是不是bug?我正在使用 Xcode8.2.1 和 swift 3 命令

characteristic.value!

不会返回值。

最佳答案

characteristic.value 返回一个Data 类型的值。这是我获取数据的方式。

        if let dataBytes = characteristic.value {
            if characteristic.uuid == CBUUID(string: "FFF1") {
                 print(dataBytes)
            } else if characteristic.uuid == CBUUID(string: "FFF2") {
                print(dataBytes)
            }
        }

关于ios - Corebluetooth 读取特性值变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540992/

相关文章:

objective-c - MBProgressHUD 完成图像 Swift

ios - CoreImageContext 的 CreateCGImage 产生了错误的 CGRect

iphone - 核心蓝牙和后台 : Detection of a device and triggering an action, 即使在后台模式下几天后?

ios - 多个 CBCentralManager 实例?

javascript - 拍照时 React-native iOS 应用程序崩溃

iphone - 自定义委托(delegate)未接听电话

ios - 网络更改可达性通知不适用于启用 VPN 的应用程序

ios - 在表格 View 单元格中添加自动布局约束。

ios - ViewController 没有名为 managedObjectContext 的成员

ios - 是否可以使用 CoreBluetooth 找到 3.0 蓝牙设备?