xcode HomeKit - 错误域=NSCocoaErrorDomain 代码=4097

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26206736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:47:26  来源:igfitidea点击:

HomeKit - Error Domain=NSCocoaErrorDomain Code=4097

iosswiftxcodehomekit

提问by KameHouse

I would like to create HMHome with HMHomeManager and addHomeWithName.

我想用 HMHomeManager 和 addHomeWithName 创建 HMHome。

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.

我读到这个问题可以解决,在“功能”选项卡上将“HomeKit”切换到“开”。但是我没有在开发人员计划中注册的开发人员 ID。

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?

有什么办法不用付80/年就可以使用这个功能??我只想学习……有什么办法可以免费注册我的Apple ID?

Thanks for all!!

谢谢大家!!

回答by Paulw11

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

在功能选项卡上打开“Homekit”表示它将做三件事 -

  1. Add the Homekit entitlement to your app id
  2. Add the Homekit entitlement to your entitlements file
  3. Link the Homekit framework
  1. 将 Homekit 授权添加到您的应用程序 ID
  2. 将 Homekit 权利添加到您的权利文件中
  3. 链接 Homekit 框架

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

没有开发人员会员资格,您无法执行 1,但您可以手动执行 2 和 3。

  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
  1. 在你的项目中选择一个文件夹,例如“Supporting files”,然后选择 File->New->File(或 Cmd-N)
  2. 从 iOS 部分选择“资源”,然后选择“属性列表”,然后单击“下一步”
  3. 将文件命名为“yourProject.entitlements”并单击“创建”
  4. 选择新创建的文件(“权利文件”)中的第一行,然后单击 + 添加新条目
  5. 输入“com.apple.developer.homekit”,类型为“Boolean”,值为“YES”
  6. 在项目导航器顶部选择您的 Xcode 项目(蓝色图标),然后转到“常规”选项卡
  7. 在底部,您将看到“链接的框架和二进制文件”。单击“+”并添加 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

不幸的是,这仍然给我带来了与您收到的相同的错误,直到我在功能中启用了 Homekit,因此您似乎需要获得付费的开发人员会员资格才能使用 Homekit

回答by KameHouse

Hello again and thanks for answering.

再次您好,感谢您的回答。

I answer myself. I managed to run my code running it from the Xcode 6 beta 3. In xcode 6 betas 1-3 you did not need any special capabilities To have to use homekit. This Beta 4 changed. You need to Have the homekit Both entitlement added to your entitlements file and your app ID.

我自己回答。我设法从 Xcode 6 beta 3 运行我的代码。在 xcode 6 betas 1-3 中,您不需要任何特殊功能就可以使用 homekit。这个 Beta 4 改变了。您需要将 homekit Both 权利添加到您的权利文件和您的应用程序 ID。

To learn is perfect. and if I decide to take the step to the AppStore, I enroll in the Apple Developer Program.

学习是完美的。如果我决定进入 AppStore,我会注册 Apple Developer Program。