iOS के लिए Home API, किसी डिवाइस को फ़ैब्रिक से कनेक्ट करने के लिए Matter हब का इस्तेमाल करते हैं. कमीशन करने के दौरान, ऐप्लिकेशन SDK टूल को एक निर्देश भेजता है और फिर हब को.
Matter डिवाइस को चालू करने के लिए:
Home APIs iOS SDK
को Matter के साथstructure.prepareForMatterCommissioning()
के लिए, कमिशन करने के अनुरोधों को तैयार करने के लिए सूचना दें. यह कमांड ये काम करेगा:- पुष्टि करें कि अनुमति दी गई है.
- पक्का करें कि हब ऑनलाइन हो और उस तक पहुंचा जा सके.
- पक्का करें कि कोई दूसरा चालू सेशन न चल रहा हो.
do { try await structure.prepareForMatterCommissioning() } catch { Logger.error("Failed to prepare for Matter Commissioning: \(error).") return }
Apple की Matter सहायता टीम से संपर्क करने के लिए,
MatterAddDeviceRequest()
के साथ अनुरोध करें.let topology = MatterAddDeviceRequest.Topology( ecosystemName: "Google Home", homes: [MatterAddDeviceRequest.Home(displayName: structure.name)] ) let request = MatterAddDeviceRequest(topology: topology)
perform()
के साथ अनुरोध करें. अगर कोई गड़बड़ी होती है, तोstructure.cancelMatterCommissioning()
का इस्तेमाल करके, कमिशन करने का अनुरोध रद्द करें.do { Logger.info("Starting MatterAddDeviceRequest.") try await request.perform() Logger.info("Successfully completed MatterAddDeviceRequest.") let commissionedDeviceIDs = try structure.completeMatterCommissioning() Logger.info("Commissioned device IDs: \(commissionedDeviceIDs).") } catch let error { structure.cancelMatterCommissioning() Logger.error("Failed to complete MatterAddDeviceRequest: \(error).") }
Apple Developer Console में
App Group ID
बनाएं, ताकि डिवाइस को चालू करते समय ऐप्लिकेशन,MatterAddDevice
एक्सटेंशन से संपर्क कर सके.इस ग्रुप आईडी का इस्तेमाल करने के लिए, आपको अपने ऐप्लिकेशन बंडल आइडेंटिफ़ायर और प्रोविज़निंग प्रोफ़ाइलों को भी अपडेट करना होगा.
शुरू करने के दौरान, ग्रुप आइडेंटिफ़ायर का इस्तेमाल करने के लिए
Home
इंस्टेंस को कॉन्फ़िगर करें.func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { Home.configure { $0.sharedAppGroup = "group.com.sample.app.commissioning" } return true }
Apple का iOS Matter ऐप्लिकेशन एक्सटेंशन लागू करें.
सैंपल कोड में, Apple के
MatterAddDeviceExtensionRequestHandler
एपीआई के सबक्लास को लागू करने का उदाहरण दिया गया है.कम से कम, एक्सटेंशन टारगेट में
GoogleHomeMatterCommissionerSDK
फ़्रेमवर्क जोड़ें और Google Home platformHomeMatterCommissioner
एपीआई को कॉल करने के लिए, तीन तरीकों को बदलें.commissionDevice
rooms
configureDevice
import MatterSupport import GoogleHomeMatterCommissionerSDK import OSLog final class RequestHandler: MatterAddDeviceExtensionRequestHandler { // The App Group ID defined by the application to share information between the extension and main app. private static var appGroup = "group.com.sample.app.commissioning" ... // MARK: - Home API commissioning handlers /// Commissions a device to the Google Home ecosystem. /// - Parameters: /// - home: The home that the device will be added to /// - onboardingPayload: The payload to be sent to the Matter Commissioning SDK to commission the device. /// - commissioningID: An identifier not used by the Home API SDK. override func commissionDevice(in home: MatterAddDeviceRequest.Home?, onboardingPayload: String, commissioningID: UUID) async throws { Logger.info("Commission Matter device with payload: '\(onboardingPayload)'.") var onboardingPayloadForHub = onboardingPayload let homeMatterCommissioner = try HomeMatterCommissioner(appGroup: RequestHandler.appGroup) try await homeMatterCommissioner.commissionMatterDevice( onboardingPayload: onboardingPayloadForHub) } /// Obtains rooms from the Home Ecosystem to present to the user during the commissioning flow. /// - Parameter home: The home that the device will be added to. /// - Returns: A list of rooms if obtained from the Google Home ecosystem or an empty list if there was an error in getting them. override func rooms(in home: MatterAddDeviceRequest.Home?) async -> [MatterAddDeviceRequest.Room] { do { let homeMatterCommissioner = try HomeMatterCommissioner(appGroup: RequestHandler.appGroup) let fetchedRooms = try homeMatterCommissioner.fetchRooms() Logger.info("Returning \(fetchedRooms.count) fetched rooms.") return fetchedRooms } catch { Logger.info("Failed to fetch rooms with error: \(error).") return [] } } /// Pushes the device's configurations to the Google Home Ecosystem. /// - Parameters: /// - name: The friendly name the user chose to set on the device. /// - room: The room identifier that the user chose to put the device in. override func configureDevice(named name: String, in room: MatterAddDeviceRequest.Room?) async { Logger.info("Configure Device name: '\(name)', room: \(room?.displayName ?? "").") do { let homeMatterCommissioner = try HomeMatterCommissioner(appGroup: RequestHandler.appGroup) await homeMatterCommissioner.configureMatterDevice( deviceName: name, roomName: room?.displayName) } catch { Logger.info("Configure Device failed with error: \(error).") } } }