我正在尝试使用swift通过蓝牙连接将字符串发送到Nordic Semiconductor开发套件(nRF52840)。核心蓝牙提供了writeValue,在外围对象上调用它。我该如何使用呢?
我在网上看过,但是找不到如何发送数据的教程或指南。
func writeValue(data: String){
//let valueString = (data as NSString).data(using: String.Encoding.utf8.rawValue)
print("Checkpoint 1")
let cafe = Data(data.utf8)
//change the "data" to valueString
if let blePeripheral = BLEControl.BLESingleton.connectedPeripheral{
print("Checkpoint 2")
if let txCharacteristic = txCharacteristic {
print("Checkpoint 3")
blePeripheral.writeValue(cafe, for: txCharacteristic, type: CBCharacteristicWriteType.withResponse)
}
}
}
'''
The Code I am using is from Nordic Semiconductor's example basic communication found on this GitHub, https://github.com/nar0909/nRFSampleSwiftApp_iOS/tree/master/Basic-Chat-master/Basic%20Chat