Characteristics with cached values must be read-only

在用CoreBluetooth 做蓝牙数据传输时,把设备设为周边设备报此错误:

Characteristics with cached values must be read-only

 

经查询是因为在构造 Characteristic 时设置了 Value,根据官方说明,当Value 不是nil 时,只能设置为只读状态。

 

Note: If you specify a value for the characteristic, the value is cached and its properties and permissions are set to be readable. Therefore, if you need the value of a characteristic to be writeable, or if you expect the value to change during the lifetime of the published service to which the characteristic belongs, you must specify the value to be nil. Following this approach ensures that the value is treated dynamically and requested by the peripheral manager whenever the peripheral manager receives a read or write request from a connected central

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。