如何将数据从iOS Swift 3应用程序写入BLE(HM-10)



我正在尝试将数据从iPhone发送到HM-10

我已经与蓝牙设备建立了连接,但是我不知道如何发送数据,这是外围委托功能吗?

当按下按钮时,固定整数(1,2,3,4...)将被发送到BLE设备一次。此外,我有滑块,我希望将滑块的值发送到

我该怎么做?

谢谢

您正在寻找此方法:

CBPeripheral.func writeValue(_ data: Data, for characteristic: CBCharacteristic, type: CBCharacteristicWriteType)

请参阅:https://developer.apple.com/reference/corebluetooth/cbperipheral/1518747-writevalue

在使用CBPerpheral.writeValue函数将数据写入设备之前,您必须发现特征,服务并保持对它们的有力引用。

苹果的教程中描述了所有内容:https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonCentralRoleTasks/PerformingCommonCentralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH3-SW1

它在 Obj-C 中,但很容易将其转换为 swift

最新更新