NSLocalizedDescription =不允许写

时间:2018-11-23 14:02:45

标签: swift bluetooth-lowenergy permission-denied

我尝试制作一个将消息从iPhone发送到Bluetooth LE模块的应用程序。但是由于某种原因,它会出现以下错误:

  

NSLocalizedDescription =不允许写

即使 blePeripheral blePeripheral!.write 的类型为CBCharacteristicWrite.withResponse ,错误表明不允许写作。为什么下面的代码对我不起作用?

func writeValue(data: String) {
    let valueString = (data as NSString).data(using: String.Encoding.utf8.rawValue)
    //change the "data" to valueString
    if let blePeripheral = blePeripheral {
        if let txCharacteristic = txCharacteristic {
            blePeripheral.writeValue(valueString!, for: txCharacteristic, type: CBCharacteristicWriteType.withResponse)
        }
    }
}

func writeCharacteristic(val: Int8) {
    var val = val
    let ns = NSData(bytes: &val, length: MemoryLayout<Int8>.size)
    blePeripheral!.writeValue(ns as Data, for: txCharacteristic!, type: CBCharacteristicWriteType.withResponse)
}

我在其中找到代码的资源是: https://learn.adafruit.com/crack-the-code/communication

0 个答案:

没有答案