Swift中HomeKist控件交互(HMCharacteristic)(六)
HMCharacteristic设置值,做控件交互
func findCharacteristicsOfService(service:HMService){
for characteristic in service.characteristics as [HMCharacteristic]{
print("???????????????????? characteristic type:\(characteristic.characteristicType)")
//HMCharacteristicTypeBrightness 灯光亮度
if characteristic.characteristicType == HMCharacteristicTypeBrightness{
if characteristic.isReadable() == false{
print("-------------不能读取")
return
}
characteristic.readValue { (error) in
if error == nil{
//
let value = characteristic.value as! Float;
print("---------------value:\(value)")
if characteristic.isWritable(){
let newValue = value - 1;
characteristic.writeValue(newValue, completionHandler: { (error) in
if(error == nil){
print("新值设置成功")
}else{
print("新值设置失败")
}
})
}
}else{
print("-------------读取失败")
}
}
}
}
}
浙公网安备 33010602011771号