-
Add support for Matter in your smart home app
The enhanced and new APIs in HomeKit enable smart home developers to integrate with the new Matter protocol in the most convenient way. Tour the Matter protocol, and discover how to set up and manage Matter accessories on our platforms and within your smart home apps.
Recursos
-
Buscar este video…
-
-
4:58 - Add a Matter accessory to your HomeKit app
home.addAndSetupAccessories() { error in if let error = error { print("Error occurred in accessory setup \(error)”) } else { print("Successfully added accessory to HomeKit") } } -
9:12 - Invocation example
let homes = proprietaryHomeStorage.homes.map { home in HMCHIPServiceHome(uuid: home.uuid, name: home.name) } let topology = HMCHIPServiceTopology(homes: homes) let setupManager = HMAccessorySetupManager() do { try await setupManager.addAndSetUpAccessories(for: topology) print("Successfully added accessory to my app”) } catch { print("Error occurred in accessory setup \(error)") } -
10:15 - Extension communication
class RequestHandler: HMCHIPServiceRequestHandler, CHIPDevicePairingDelegate { // . . . override func pairAccessory(in: HMCHIPServiceHome, onboardingPayload: String) async throws -> Void { // iOS is instructing the extension to pair the accessory via CHIP.framework } // . . . } -
10:39 - Extension communication
class RequestHandler: HMCHIPServiceRequestHandler, CHIPDevicePairingDelegate { // . . . override func rooms(in: HMCHIPServiceHome) async throws -> [HMCHIPServiceRoom] { // iOS is querying for a room list that corresponds to the given home } // . . . } -
11:03 - Extension communication
class RequestHandler: HMCHIPServiceRequestHandler, CHIPDevicePairingDelegate { // . . . override func configureAccessory(named accessoryName: String, room accessoryRoom: HMCHIPServiceRoom) async throws -> Void { // iOS is instructing the extension to apply configuration via CHIP.framework. } // . . . } -
11:27 - Extension communication
class RequestHandler: HMCHIPServiceRequestHandler, CHIPDevicePairingDelegate { override func rooms(in: HMCHIPServiceHome) async throws -> [HMCHIPServiceRoom] { // iOS is querying for rooms that match the given home. These rooms will be shown in system UI and the selection will be vended back to your extension's `configureAccessory` function } override func pairAccessory(in: HMCHIPServiceHome, onboardingPayload: String) async throws -> Void { // iOS is instructing the extension to pair the accessory via CHIP.framework } override func configureAccessory(named accessoryName: String, room accessoryRoom: HMCHIPServiceRoom) async throws -> Void { // iOS is instructing the extension to apply configuration via CHIP.framework. } } -
14:27 - Status and Control
let controller = CHIPDeviceController.shared() do { let device = try controller.getPairedDevice(accessoryDeviceID) let onOffCluster = CHIPOnOff(device: device, endpoint: lightEndpoint, queue: DispatchQueue.main) onOffCluster?.toggle({ (error, values) in // Error handling code here }) onOffCluster?.readAttributeOnOff(responseHandler: { error, response in if let state = response?[VALUE_KEY] as? NSInteger { updateLightState(state: state) } }) } catch { print("Error occurred in accessory control \(error)") }
-