HomeKit - Error Domain=NSCocoaErrorDomain Code=4097

KameHouse picture KameHouse · Oct 5, 2014 · Viewed 7.7k times · Source

I would like to create HMHome with HMHomeManager and addHomeWithName.

manager.addHomeWithName("Casa", completionHandler:
{
    (home:HMHome!, error:NSError!) in
    if error != nil {
        NSLog("Failed adding home, Error:\(error)")
    } else {
        NSLog("New Home \(home)")
    }
})

When the application is run I am getting the following error instead of creating Home

Failed adding home, Error:Error Domain=NSCocoaErrorDomain Code=4097
"The operation couldn’t be completed. (Cocoa error 4097.)"
(connection to service named com.apple.homed.xpc)

I read than this problem can be solved switching "HomeKit" to "On" at the "Capabilities" tab. But I don't have a developer ID that is enrolled in a Developer Program.

There is any way to use this functionality without pay 80€/year?? I only want to learn... There is any way to enroll my Apple ID in free mode?

Thanks for all!!

Answer

Paulw11 picture Paulw11 · Oct 5, 2014

Turning on "Homekit" on the capabilities tab says it will do three things -

  1. Add the Homekit entitlement to your app id
  2. Add the Homekit entitlement to your entitlements file
  3. Link the Homekit framework

You can't do 1 without the developer membership, but you can do 2 & 3 manually.

  1. Select a folder in your project, such as "Supporting files" and select File->New->File (or Cmd-N)
  2. Select "Resource" from the iOS section and then select "Property List" and click "Next"
  3. Name the file "yourProject.entitlements" and click "Create"
  4. Select the first line in newly created file ("Entitlements file") and click the + to add a new entry
  5. Enter "com.apple.developer.homekit" with type "Boolean" and value "YES"
  6. Select your Xcode project (Blue icon) at the top of the project navigator and go the "General" tab
  7. At the bottom your will see "Linked Frameworks and Binaries". Click "+" and add the Homekit.framework

Unfortunately this still gave me the same error you received, until I enabled Homekit in capabilities, so it seems you will need to get a paid developer membership to work with Homekit