HomeKit点滴

最近在研究HomeKit,在更改某个特征值的时候:

当设置了HMAccessoryDelegate的delegate后,在App中,改变HMCharacteristic的特征值时,

- (void)writeValue:(nullable id)value completionHandler:(void (^)(NSError * __nullable error))completion;

代理方法

- (void)accessory:(HMAccessory *)accessory service:(HMService *)service didUpdateValueForCharacteristic:(HMCharacteristic *)characteristic

是不会被触发的。

那么该方法在什么时候被触发呢?当App运行时,特征值被从他的途径修改的时候,比如通过设备的物理开关,才会触发App的改代理方法,目的是App UI与设备保持一致。

详细可参见苹果官方的描述:

Discussion
This method is called as a result of a change in value initiated by the accessory. Programmatic changes initiated by the app do not result in this method being called.

https://developer.apple.com/documentation/homekit/hmaccessorydelegate/1615286-accessory?language=objc

posted @ 2017-11-27 21:58  NOIP/NOI辅导  Views(225)  Comments(0Edit  收藏  举报