// Checks to see if an action already exists to modify the same characteristic // as the action passed in. If such an action exists, the method tells the // existing action to update its target value. Otherwise, the new action is // simply added to the action set. void AddAction(HMCharacteristicWriteAction action, HMActionSet actionSet, Action <NSError> completion) { var existingAction = ExistingActionInActionSetMatchingAction(action); if (existingAction != null) { existingAction.UpdateTargetValue(action.TargetValue, completion); } else { actionSet.AddAction(action, completion); } }
// Checks to see if there is already an HMCharacteristicWriteAction in // the action set that matches the provided action. HMCharacteristicWriteAction ExistingActionInActionSetMatchingAction(HMCharacteristicWriteAction action) { var actionSet = ActionSet; if (actionSet != null) { foreach (var existingAction in actionSet.Actions.Cast <HMCharacteristicWriteAction>()) { if (action.Characteristic == existingAction.Characteristic) { return(existingAction); } } } return(null); }
// Checks to see if there is already an HMCharacteristicWriteAction in // the action set that matches the provided action. HMCharacteristicWriteAction ExistingActionInActionSetMatchingAction (HMCharacteristicWriteAction action) { var actionSet = ActionSet; if (actionSet != null) { foreach (var existingAction in actionSet.Actions.Cast<HMCharacteristicWriteAction>()) { if (action.Characteristic == existingAction.Characteristic) return existingAction; } } return null; }
// Checks to see if an action already exists to modify the same characteristic // as the action passed in. If such an action exists, the method tells the // existing action to update its target value. Otherwise, the new action is // simply added to the action set. void AddAction (HMCharacteristicWriteAction action, HMActionSet actionSet, Action<NSError>completion) { var existingAction = ExistingActionInActionSetMatchingAction (action); if (existingAction != null) existingAction.UpdateTargetValue (action.TargetValue, completion); else actionSet.AddAction (action, completion); }