Problems creating a Writable attribute in the basic bluetooth structure

I am new to the Core Bluetooth Framework. I am developing an application that acts as a peripheral. I need an application to notify the sign value to the signed centers, and also record the sign value to the connected centers. I set the value of the characteristic when it is created. The problem is that when I set the property of a characteristic for notification or recording, it shows the error "Characteristics with cached values ​​should 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!

}
+4
source share
2 answers

-nil value CBMutableCharacteristic, " ", , , .

CBMutableCharacteristic init -

value - , . nil, .

nil CBMutableCharacteristic. didReceiveReadRequest CBPeripheralManagerDelegate.

, , updateValue CBPeripheralManager , .

" " Bluetooth

+6

, , BLE:

:

let serviceUUID = CBUUID(string: kServiceUUID)
let service = CBMutableService(type: serviceUUID, primary: true)

:

let characteristicUUID = CBUUID(string: kCharacteristicUUID)
let properties: CBCharacteristicProperties = [.Notify, .Read, .Write]
let permissions: CBAttributePermissions = [.Readable, .Writeable]
let characteristic = CBMutableCharacteristic(
    type: characteristicUUID,
    properties: properties,
    value: nil,
    permissions: permissions)

:

service.characteristics = [characteristic1, characteristic2]

:

peripheralManager.addService(service)

0

All Articles