0

The following code is used to create a home kit automation that switches off an outlet. Starting on iOS 16 it returns an error (HMErrorCodeObjectNotAssociatedToAnyHome, code 12) when the trigger is told to add the action set.

I marked the line using // error, "code 12" (HMErrorCodeObjectNotAssociatedToAnyHome). Also, HKActionSetCreateShouldContinue() is just a function to log errors and returns true if the error was <nil>.

The error first appeared in iOS 16, the same code runs smooth on iOS 15. I did not find any complaints about such an error in Apple's forums.

Does anyone have the same issue and/or know what's wrong for iOS 16?

// fireDate is rastered to minutes. in example from 1669971067.404232 to 1669971060
NSDate* const fireDate = [NSDate ...]

HMTimerTrigger* const trigger = [[HMTimerTrigger alloc] initWithName:triggerName
                                                            fireDate:fireDate
                                                            timeZone:nil
                                                          recurrence:nil
                                                  recurrenceCalendar:nil];

[home addActionSetWithName:actionSetName
         completionHandler:^(HMActionSet* _Nullable actionSet, NSError* _Nullable error) {

     if (!HKActionSetCreateShouldContinue(block, error, created, @"home/addActionSet")) {
         return;
     }

     [actionSet addAction:switchOffAction
        completionHandler:^(NSError* _Nullable add_char_error) {

            /* Only check for errors and log */
            HKActionSetCreateShouldContinue(block, add_char_error, created, @"actionSet/switchOffAction");

        }];


     [home addTrigger:trigger
           completionHandler:^(NSError* _Nullable home_error) {

         if (!HKActionSetCreateShouldContinue(block, home_error, created, @"home/addTrigger")) {
             return;
         }

         [trigger addActionSet:actionSet
             completionHandler:^(NSError* _Nullable trigger_error) {
         // error, "code 12" (HMErrorCodeObjectNotAssociatedToAnyHome)

             if (!HKActionSetCreateShouldContinue(block, trigger_error, created, @"trigger/addActionSet")) {
                 return;
             }

             [trigger enable:YES
                 completionHandler:^(NSError* _Nullable error) {

                 if (!HKActionSetCreateShouldContinue(block, home_error, created, @"trigger/enable") || block == nil) {
                     return;
                 }

                 dispatch_async(dispatch_get_main_queue(), ^{
                     block(actionSet, trigger, switchOffAction);
                 });
             }];
         }];
     ;
}];
Anticro
  • 685
  • 4
  • 12

0 Answers0