我正在使用 Xcode 7.2 和 HomeKit Accessory Simulator 版本 1.3 (77.1)
我的 HomeKit 代码中有以下代码
//MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let accessory = accessories[indexPath.row] as HMAccessory
if let room = homeManager.primaryHome?.rooms.first as HMRoom? {
homeManager.primaryHome?.addAccessory(accessory, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to home. \(error?.localizedDescription)")
} else {
self.homeManager.primaryHome?.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to room. \(error?.localizedDescription)")
} else {
self.navigationController?.popViewControllerAnimated(true)
}
})
}
})
}
}
当我单击 UITableViewCell 时,它会弹出“添加附件”对话框,在我输入配对/设置代码后,它会给出错误:
Issues adding accessory to home. Optional("Operation in progress.")
有时我会得到
Issues adding accessory to home. Optional("Client request error when communicating with accessory.")
当我在 iPhone (iOS 9.2.1) 上运行相同的代码时,出现以下错误
Something went wrong when attempting to create our home. Optional("Cloud data sync is in progress.")
这是 HomeKit 中的已知问题吗?或者是 HomeKit 硬件模拟器中的错误?有解决方法/修复吗?
最佳答案
你可能需要改变
if let room = homeManager.primaryHome?.rooms.first as HMRoom? {
至
if let room = homeManager.primaryHome?.rooms.first as? HMRoom {
我是否正确地阅读了这段代码?
<小时/>但是如果条件被分开并且使用未包装的对象,它会更具可读性和可调试性。假设 HMRoom 是一个类:
if let home = homeManager.primaryHome,
room = home.rooms.first as? HMRoom {
home.addAccessory(accessory, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to home. \(error?.localizedDescription)")
} else {
home.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to room. \(error?.localizedDescription)")
} else {
self.navigationController?.popViewControllerAnimated(true)
}
})
}
})
}
关于ios - 可选 ("Operation in progress.") 当使用 HomeKit 在 iOS 模拟器上添加配件时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35086311/