我正在使用 xcode 7 beta 4,HomeKit Accessory 模拟器版本 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()
}
}