I am new to Core Bluetooth Framework. I am developing an application that act as peripheral. I need the app to notify characteristic value to subscribed centrals and also write the value of characteristic by the connected central. I am setting the value of characteristic while creating it. The issue is when i am setting the property of characteristic to notify or write it is showing error "Characteristics with cached values must be read-only". Can anybody help me ?
var charValue = characteristicDetail["value"] as String
var charProperties:CBCharacteristicProperties = getProperty(characteristicDetail["properties"] as String )
let data = charValue.dataUsingEncoding(NSUTF8StringEncoding)
var characteristic = CBMutableCharacteristic(type: charId, properties: charProperties, value: data, permissions: CBAttributePermissions.Readable)
func getProperty(string:String) -> CBCharacteristicProperties
{
var propertyString:CBCharacteristicProperties?
switch string{
case "r","R":
propertyString = CBCharacteristicProperties.Read
case "w","W":
propertyString = CBCharacteristicProperties.Write
case "n","N":
propertyString = CBCharacteristicProperties.Notify
case "i","I":
propertyString = CBCharacteristicProperties.Indicate
case "rw","wr","WR","RW":
propertyString = CBCharacteristicProperties.Read|CBCharacteristicProperties.Write
case "rn","nr","NR","RN":
propertyString = CBCharacteristicProperties.Read|CBCharacteristicProperties.Notify
case "wn","nw","NW","WN":
propertyString = CBCharacteristicProperties.Write|CBCharacteristicProperties.Notify
default:
propertyString = CBCharacteristicProperties.Read
}
return propertyString!
}