2

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.

Shrikant K
  • 1,988
  • 2
  • 23
  • 34

3 Answers3

0

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

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.

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.

axl coder
  • 739
  • 3
  • 19
0

Not sure this is still relevant to anybody, but in order to have this fixed you have to add this capability to your provisioning profile on your apple developer account -> Certificates, Identifier and Profiles -> choose your identifier -> go to the Additional Capabilities tab and you will find there the HomeKit AllowSetupPayload.

I am not sure why this is not included within the normal HomeKit but that's what fixed it for me.

0

I got a help email from Apple, how to enable com.apple.developer.homekit.allow-setup-payload, the entitlement itself is managed by the MFI team, so you'd need to reach out to your MFI representative to request the entitlement.

jianhai
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Vikram Parimi Sep 17 '22 at 18:31