首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用HMHome添加HomeKit

使用HMHome添加HomeKit
EN

Stack Overflow用户
提问于 2014-10-15 18:06:58
回答 3查看 657关注 0票数 0

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

代码语言:javascript
复制
HomeKitDemoApp[22635:1632134] Add home error:Error Domain=HMErrorDomain Code=49 "The operation couldn’t be completed. (HMErrorDomain error 49.)"

我的代码是:

代码语言:javascript
复制
    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()
    }

 }

希望任何人都有想法并能帮助我。谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-03-18 08:05:48

添加主页的最大限制是10。Homekit将不允许添加超过10个主页。

票数 0
EN

Stack Overflow用户

发布于 2015-02-13 21:41:44

看来你的家太多了。我不知道限制是什么,但当你重建应用程序时,房屋不会被移除。它们(以及所有其他的homekit数据)保存在一个连接到iCloud帐户的共享数据库中。

你建了多少栋房子?

票数 0
EN

Stack Overflow用户

发布于 2015-10-18 18:40:35

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

hth

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26389194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档