在用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