我想知道您是否可以设置以编程方式启用附件的代码?我在这一刻使用:
import UIKit
import Foundation
import HomeKit
let homeManager = HMHomeManager()
func addAccessory () {
if let home = homeManager.primaryHome {
for room in home.rooms {
if room.name == "Kitchen" {
homeManager.primaryHome?.addAccessory(accessory, completionHandler: { (error) -> Void in
if error != nil {
print("ERROR 1 \(error?.localizedDescription)")
}else {
self.homeManager.primaryHome?.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in
if error != nil {
print("ERROR 2 \(error?.localizedDescription)")
} else {
print("Accessory Add successfully")
}}}}
}
我不会使用 Apple 提供的常用视图来输入代码。