I am developing app which manage BLE device. I am trying to write data in didDiscoverCharacteristicsFor
method like below.
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if let characteristics = service.characteristics {
for characteristic in characteristics {
if characteristic.uuid == CBUUID(string: Common.PinUUID) {
var varInt = 0
let data = Data.init(bytes: &varInt, count: 1);
peripheral.writeValue(data, for: characteristic, type: .withResponse)
}
}
}
When I try to write data on characteristic then I got error like below.
<CBCharacteristic: 0x283b213e0, UUID = 47E9EE30-47E9-11E4-8939-164230D1DF67, properties = 0x8, value = (null), notifying = NO> - Optional("Writing is not permitted.")
My characteristic is Write only type. I don't know why it shows error like this.
Also when I try to read data then I call like below.
if characteristic.uuid == CBUUID(string: Common.TemperatureDataUUID) {
print(characteristic)
peripheral.readValue(for: characteristic)
}
I got error like below,
<CBCharacteristic: 0x283e77300, UUID = 47E9EE2B-47E9-11E4-8939-164230D1DF67, properties = 0xA, value = (null), notifying = NO> - Optional("Reading is not permitted.")
How to solve it not finding any solution? Please help.
from Error Domain=CBATTErrorDomain Code=2 "Reading is not permitted." UserInfo={NSLocalizedDescription=Reading is not permitted.}
No comments:
Post a Comment