如何在 iOS 中获取 HM-10 Bluetooth LE 的特性

How to get the characteristic(s) of HM-10 Bluetooth LE in iOS

我正在尝试将一些数据从 iOS 设备发送到连接到 arduino 的 HM-10 蓝牙 LE 模块。问题是在连接到模块后 discoverServices 没有 return 服务的特征。

    func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
    if(error != nil) {
        print(error?.description)
    }
    for service in peripheral.services! {
        let thisService = service as CBService
        print("Service: \(thisService.description)")
        print("Characteristic: \(thisService.characteristics)")
    }
}

这输出:

Service: <CBService: 0x137e84ea0, isPrimary = YES, UUID = FFE0>
Characteristic: nil

我是这个 arduino 的初学者,也是 iOS。因此,欢迎提出任何建议。也许有一种方法可以在不知道特征的情况下写入蓝牙模块...我不知道。

终于找到答案了。由于我对 CoreBluetooth 框架的初步了解,我忘记在 didDiscoverServices 中调用 discoverCharacteristics。好吧,我真的是边做边学。 (我以某种方式认为 discoverServices 会调用 discoverCharacteristics 本身。)