How to add HomeKit accessory using HMAccessoryPayLoad?

不打扰是莪最后的温柔 提交于 2020-06-23 14:09:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!