如何使用HMAccessoryPayLoad添加HomeKit附件? [英] How to add HomeKit accessory using HMAccessoryPayLoad?

查看:123
本文介绍了如何使用HMAccessoryPayLoad添加HomeKit附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在使用HomeKit,我想使用HomeKit实现一项功能.

Hello currently I'm working on HomeKit, I want achieve one feature using HomeKit.

我的要求是不使用要添加附件的QR码.由于每个配件都有自己的网址,例如与QR码关联的X-HM://XXXXXXXXX,即HMAccessoryPayLoad.

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

如何使用HMAccessoryPayLoad添加和设置附件

打开HomeKit X-HM://URL sheme

因此,根据文档,我尝试使用以下代码添加附件.我希望可以使用此代码直接添加附件,而无需打开默认的HomeKit相机视图.

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.

推荐答案

我从Apple支持部门获得了答案,因为基本上我处于相同的情况.

I had the answer from Apple Support, because basically I was in the same situation.

如果您未添加"com.apple.developer.homekit.allow-setup-payload"授权,则该API基本无法使用值等于True.

Basically this API doesn't work if you don't add the Entitlement "com.apple.developer.homekit.allow-setup-payload" with value equals to True.

我知道,没有关于此的文档,但这就是它.

I know, there is no documentation regarding this, but this is it.

此外,重点是,我目前不知道如何将此权利添加到供应配置文件中.我已请求Apple支持,我将更新此线程 Xamarin iOS-HomeKit集成只要我有答案.

Moreover, the point is that I don't know at the moment how to add this entitlement to the provisioning profile. I have asked to Apple support, and I will update this thread Xamarin iOS - HomeKit integration as soon as I have the answer.

您会看到这是正确的方法,因为如果您在模拟器上尝试它,它将起作用.关键是要在真实设备上使用它,我们需要配置文件中的授权.

You can see that this is the right approach because if you try it on the simulator it will work. The point is that to use it on a real device we need the entitlement in the provisioning profile.

这篇关于如何使用HMAccessoryPayLoad添加HomeKit附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆