1

我正在尝试在家中添加访问权限这是我的代码

    home.addAccessory(accessory, completionHandler: {[weak self]
            (error: NSError!) in

            let strongSelf = self!

            if error != nil{
                println("Failed to add the accessory to the home")
                println("Error = \(error)")
            } else {
                println("Successfully added the accessory to the home")
                println("Assigning the accessory to the room...")
                strongSelf.home.assignAccessory(accessory,
                    toRoom: strongSelf.room,
                    completionHandler: {(error: NSError!) in

                        if error != nil{
                            println("Failed to assign the accessory to the room")
                            println("Error = \(error)")
                        } else {
                            println("Successfully assigned the accessory to the room")

                            strongSelf.findServicesForAccessory(accessory)

                        }

                })
            }

        })

但它告诉我错误

警报

并且无法在家里添加配件。

  println("Failed to add the accessory to the home")

上面提到的语句确实执行。它不要求提供附件设置代码。

4

1 回答 1

3

您所解释的内容对于找到确切原因并没有太大帮助,我多次遇到相同的错误并且错误日志还不够,但是我通过以下步骤修复了它。

  • 重置模拟器或删除您的应用程序
  • 运行您的应用程序并尝试再次添加附件。

据我了解,此错误仅出现在模拟器环境中,因为您将在真实设备上运行应用程序并使用真实配件而不是Home Kit 配件模拟器对其进行测试,此问题可能不会出现(尚未在设备上测试)。

我希望它对你有帮助。

于 2014-12-11T12:07:21.207 回答