简体   繁体   English

使用HomeKit添加HMHome

[英]Adding a HMHome with HomeKit

I'm trying to add a Home to my HomeKitDemoApp. 我正在尝试向HomeKitDemoApp添加房屋。 When i'm installing the app the first time on a device or simulator i'm getting the popup that HomeKitDemoApp like to access my accessory data.I press OK it seams to work and rooms are added to my tableview. 当我第一次在设备或模拟器上安装该应用程序时,我会弹出弹出窗口,表明HomeKitDemoApp喜欢访问我的附件数据。按OK,它可以正常工作,并且房间已添加到我的表视图中。 After i rebuild the app on the same device or simulator device i don't geht the rooms into my tableview. 在同一设备或模拟器设备上重建应用程序后,我不会将房间塞入我的表视图中。 Now i get an error: 现在我得到一个错误:

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

My code is: 我的代码是:

    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()
    }

 }

hope anyone has an idea and can help me. 希望任何人有一个主意并能帮助我。 thank you. 谢谢。

It appears you have too many homes. 看来您有太多房屋。 I'm not sure what the limit is, but the homes are not removed when you rebuild the app. 我不确定限制是多少,但是在重建应用程序时房屋不会被移除。 They (along with all other homekit data) persist in a shared database that is tied to an iCloud account. 它们(以及所有其他homekit数据)保存在与iCloud帐户绑定的共享数据库中。

How many homes did you create? 您创造了多少座房屋?

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

HomeKit will allow to add a maximum of 10 homes. HomeKit将允许最多添加10个房屋。 To delete all of the home data from your iOS device and iCloud, go to Settings > Privacy > HomeKit and tap "Reset HomeKit Configuration". 要从iOS设备和iCloud删除所有家庭数据,请转到设置>隐私> HomeKit,然后点击“重置HomeKit配置”。 Removing the app from the device and re-installing it will not clear the HomeKit Configuration. 从设备中删除应用程序并重新安装它不会清除HomeKit配置。

hth hth

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM