Search code examples
iosswifthomekit

HMAccessoryDelegate Method not called


I want to get value of updatable characteristics for particular accessory.

So I am using func accessory(accessory: HMAccessory!, service: HMService!, didUpdateValueForCharacteristic characteristic: HMCharacteristic!) method.

But this method is not called. Another method from same delegate is being called. What should be the problem?


Solution

  • Enabled notification for the characteristic in viewWillAppear.

    for (HMCharacteristic *thisCharacteristic in characteristicsArray) {
        if ([thisCharacteristic.properties containsObject:HMCharacteristicPropertySupportsEventNotification]) {
            [thisCharacteristic enableNotification:TRUE completionHandler:^(NSError *error) {
                if (error) {
                    NSLog(@"Error while enabling notification");
                }
                else    {
                    NSLog(@"Notification enabled");
                }
            }];
        }
    

    Also Disable the notification in viewWillDisappear