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!}解决方法 如果在创建CBMutableCharacteristic时指定非零值,则它是“缓存特征”,并且如错误消息所示,您不能在以后更改该值.
从CBMutableCharacteristic init方法的文档 –
value – The characteristic value to be cached. If nil,the value is dynamic and will be requested on demand.
创建CBMutableCharacteristic时指定nil-在dIDReceiveReadRequest CBPeripheralManagerDelegate方法中请求时提供值.
如果您有已订阅该特性的中心,那么每当值发生变化时,您还应该在CBPeripheralManager上调用updateValue.
请务必阅读Core Bluetooth Programming Guide中的执行常见外设角色任务一节
总结以上是内存溢出为你收集整理的ios – 在Core Bluetooth Framework中创建可写特性的问题全部内容,希望文章能够帮你解决ios – 在Core Bluetooth Framework中创建可写特性的问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)