HomeKit 自动化与树莓派交互应用开发
1. HomeKit 自动化开发
在 HomeKit 的自动化开发里,要在 viewDidLoad
方法中设置好 services
数组后调用 enableNotifications(true)
来开启通知,在 viewWillDisappear
方法中调用 enableNotifications(false)
来关闭通知。
1.1 实现 UITableView 方法
表格视图的数据源是 services
数组,表格的分区数量由服务数量决定,每个分区的行数由每个服务的特征数量决定,代码如下:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return services.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return services[section].characteristics.count
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) ->