问题
Hello currently I'm working on HomeKit, I want achieve one feature using HomeKit.
My requirement is without using QR code I want to add accessory. As every accessory has it's own URL like e.g. X-HM://XXXXXXXXX
associated with QR code, i.e. HMAccessoryPayLoad
.
The very similar questions which are unanswered I can see
How to Add and Set up accessory using HMAccessoryPayLoad
Open HomeKits X-HM:// URL sheme
So as per documentation I tried using below code to add accessory. I hope using this code we can add accessory directly without opening default HomeKit camera view.
if #available(iOS 11.3, *) {
let payload = HMAccessorySetupPayload.init(url: URL.init(string: "X-HM://XXXXXXXXXX")!)
home!.addAndSetupAccessories(with: payload!) { (accessories, error) in
if let error = error {
print("Error from addAndSetupAccessories:",error)
} else {
print("The accessory is added.")
}
}
} else {
// Fallback on earlier versions
}
After running this code it's not giving either error or success. I tried checking console but it is empty.
Can you please help me to add accessory using payload & without using code or opening default camera view.
来源:https://stackoverflow.com/questions/62470261/how-to-add-homekit-accessory-using-hmaccessorypayload