0

I have a problem while adding a new accessory to the home kit. When I call below metho then it gives me error or success. But I want an accessory object when it is successfully onboarded. So, Is there any way to get the accessory object which is successfully added via the below method?

Right now, I have found only this method. Another via payload method is deprecated from iOS15. If there is any other method then this also you can suggest me. But I need a method for setup and adding accessories that opened the default view of the home kit.

fun addAccessory() {
 home.addAndSetupAccessories { error in
  if let error = error {
   print("error")
  }
  else {
   print("success added")
  }
 }
}```
Mirant
  • 308
  • 2
  • 13

1 Answers1

0

You can get the added accessories, provided you follow the HMHomeDelegate, the sample code

home.delegate = self

You will get the added accessories in the delegate method home(_:didAdd:)

func home(_ home: HMHome, didAdd accessory: HMAccessory) {
         // accesstroy: the new accessory
     }

Also, after iOS15.4, you can get homeIdentifier and accessory identifier in the callback of the performAccessorySetup(using:completionHandler:)

jianhai
  • 1
  • 1