0

我正在尝试将 Home 添加到我的 HomeKitDemoApp。当我第一次在设备或模拟器上安装应用程序时,我得到了 HomeKitDemoApp 喜欢访问我的附件数据的弹出窗口。我按 OK,它接缝开始工作,房间被添加到我的 tableview 中。在同一设备或模拟器设备上重建应用程序后,我不会将房间放入我的 tableview 中。现在我得到一个错误:

HomeKitDemoApp[22635:1632134] Add home error:Error Domain=HMErrorDomain Code=49 "The operation couldn’t be completed. (HMErrorDomain error 49.)"

我的代码是:

    import Foundation
import UIKit
import HomeKit

class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, HMHomeManagerDelegate{

    var homeManager:HMHomeManager = HMHomeManager()

    @IBOutlet var homesTableView: UITableView!

    var homes = [AnyObject]()

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }


    @IBAction func addHome(sender: AnyObject) {
        let alert:UIAlertController = UIAlertController(title: "Zuhause hinzufügen", message: "Neues Zuhause zu HomeKit hinzufügen", preferredStyle: .Alert)


        alert.addTextFieldWithConfigurationHandler(nil)
        alert.addAction(UIAlertAction (title: "abbruch", style: UIAlertActionStyle.Cancel, handler: nil))
        alert.addAction(UIAlertAction(title: "hinzufügen", style: UIAlertActionStyle.Default, handler:
            {
                (action:UIAlertAction!) in
                let textField = alert.textFields?[0] as UITextField

                //create home with the typed name
                    self.homeManager.addHomeWithName(textField.text, completionHandler:
                        {
                            (home: HMHome!,error )in
                            if let error = error {
                                NSLog("Add home error:\(error)")
                            }else{
                                println("im here in reloaddata")
                                self.homes.append(home)
                                self.homesTableView.reloadData()
                            }
                        }
                    )

        }))

        self.presentViewController(alert, animated: true, completion: nil)

    }

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("CustomHomeCell", forIndexPath: indexPath) as UITableViewCell
        let home = self.homeManager.homes?[indexPath.row] as HMHome
        cell.textLabel?.text = home.name
        return cell

    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return homes.count
    }
    // #pragma mark - HMHomeManager Delegate

    func homeManagerDidUpdateHomes(manager: HMHomeManager!) {

        self.homes = manager.homes

        self.homesTableView.reloadData()
    }

 }

希望任何人有一个想法,可以帮助我。谢谢你。

4

3 回答 3

0

看来你家太多了。我不确定限制是多少,但是重建应用程序时不会删除房屋。它们(连同所有其他 homekit 数据)保存在与 iCloud 帐户绑定的共享数据库中。

你创造了多少家?

于 2015-02-13T21:41:44.833 回答
0

添加家庭的最大限制是 10。Homekit 不允许添加超过 10 个家庭。

于 2015-03-18T08:05:48.727 回答
0

HomeKit 最多允许添加 10 个家庭。要从您的 iOS 设备和 iCloud 中删除所有家庭数据,请前往“设置”>“隐私”>“HomeKit”,然后点击“重置 HomeKit 配置”。从设备中删除应用程序并重新安装它不会清除 HomeKit 配置。

hth

于 2015-10-18T18:40:35.153 回答