HomeKit找到新的附件委托方法不起作用,为什么?

时间:2015-09-23 05:07:33

标签: ios iphone ios9 homekit

我正在使用xcode 7 beta 4,HomeKit附件模拟器1.3版。

我为项目启用了HomeKit功能,添加了具有配置文件的homekit权利。使用相同的配置文件和权利,它可以在我的另一个项目中正常工作,但不适用于我当前的项目。

我的代码是

    class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,HMAccessoryBrowserDelegate {


    let accessoryBrowser = HMAccessoryBrowser()
    let homeManager = HMHomeManager()
    var accessories: [HMAccessory] = []

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        accessoryBrowser.delegate = self
        accessoryBrowser.startSearchingForNewAccessories()

        tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

    }

    func accessoryBrowser(browser: HMAccessoryBrowser, didFindNewAccessory accessory: HMAccessory) {
        if !localAccessoriesContains(accessory) {
            accessories.append(accessory);
            tableView.reloadData()
            NSLog("new accessory found")


        }
    }

    func accessoryBrowser(browser: HMAccessoryBrowser, didRemoveNewAccessory accessory: HMAccessory) {
        removeFromLocalAccessories(accessory)
        tableView.reloadData()
    }
} 

0 个答案:

没有答案