Prepare for Integration with Matter Device
Version: 20230719
Online Version
Prepare for Integration with Matter Device
Before the integration of a Matter device into your project, you must configure the project. For the pairing process implemented by Tuya, Matter devices are classified into Tuya-enabled Matter devices and third-party Matter devices. For a thirdparty Matter device, add an extension target to your Xcode project.
Prerequisites
- Before you start, the steps in Fast Integration with Smart Life App SDK must be finished.
- If you require UI BizBundles, the version of Smart Life App SDK must be the same as that of the UI BizBundles to ensure stable pairing and control of devices.
Configure and integrate with main project
2.1 Configure entitlements
- Open the project settings in Xcode.
- Choose the target of the main project> Signing& Capabilities, and click + Capability.
- Add the entitlement Matter Allow Setup Payload that is used to handle parsing of Matter QR codes.
- Add the App Groups entitlement that is used to share data with Matter Extension Target. Set App Group ID to the same value as Matter Extension Target.
- Add the Background Modes entitlement and select Uses Bluetooth LE accessories that is used to ensure stable communication over Bluetooth.
The following figure shows these steps.
2.2 Configure Info.plist
- Open the project settings in Xcode.
- Choose the target of the main project> Info> Custom iOS Target Prop- erties.
- Privacy – Bluetooth Peripheral Usage Description
Add the entitlement NSBluetoothPeripheralUsageDescription that is used for privacy and permission purposes and to provide a user-facing description of the reason for requesting access to Bluetooth peripherals. - Bonjour services
Matter has a strong dependency on communication on a LAN. In light of this, you must configure Bonjour services in the file Info.plist of the main project. Example:
2.3 Use CocoaPods for fast integration
- We recommend that you update CocoaPods to the latest version.
- Add the following code block to the Podfile:
- In the root directory of your project, run pod update.
For more information about CocoaPods, see CocoaPods Guides.
2.4 Initialize module
Follow the instructions in Fast Integration with Smart Life App SDK for iOS and initialize the SDK. Then, initialize the Matter module.API description
Parameters
Parameter | Description |
configKey | The App Group ID of the project. |
Example
Objective-C:Swift:
Configure and integrate with Extension Target
3.1 Things to note
- Xcode 14.1 or later is required.
- iOS 16.1 or later is required.
- Create Matter Extension Target and use the default code file to perform the steps described in the following sections.
- Matter Extension Target supports Swift projects only.
3.2 Configure entitlements
- Open the project settings in Xcode.
- Choose the target of the main project> Signing& Capabilities, and click + Capability.
- Add the App Groups entitlement that is used to share data with the target of the main project. Set App Group ID to the same value as the target of the main project.
3.3 Use CocoaPods for fast integration
- We recommend that you update CocoaPods to the latest version.
- Add the following code block to the Podfile:
- In the root directory of your project, run pod update.
For more information about CocoaPods, see CocoaPods Guides.
3.4 Initialize module
Open the file RequestHandler.swift in the ExtensionTarget project and rewrite the init method.API description
Parameters
Parameter | Description |
configKey | The App Group ID of the project. |
Example
Swift:3.5 Use Thing Smart Matter Extension Kit
After the Matter Extension Target project is generated, the file RequestHandler.swift appears in the Extension project. Use the API methods provided by the system and call ThingSmartMatterExtensionKit as shown in the following example.
- Import ThingSmartMatterExtensionKit into the project.
- Make API requests with the methods that are automatically generated by the system, as shown in the following code block.
The callback methods in Request Handler.swift are automatically generated by the system and cannot be modified.
Configure Matter capabilities
Due to the characteristics of a Matter device, all its capabilities are implemented based on Matter fabrics. Before a Matter device can be paired, controlled, or managed, you must make API requests to configure basic information about the Matter device. This configuration must be finished before any Matter services are implemented.
A fabric is a group of networked devices (also known as nodes) that share the same security domain. This enables secure communications among these nodes within the fabric. Nodes in the same fabric share the same Certificate Authority’s (CA) top-level certificate (Root of Trust) and within the context of the CA, a unique 64-bit identifier named Fabric ID.
4.1 Sequence diagram
The following figure shows the sequence in which basic Matter information is configured.4.2 Prepare information about fabric
Information about Matter is bound with homes. Therefore, at the end of the operation of switching between homes or initially loading a home, call – loadFabricWithSpaceId to get information about the fabric that is bound with the home.
API descriptionParameters
Parameter | Description |
spaceId | The value of HomeID for the current home. |
success | The success callback. |
failure | The failure callback. |
Example
Objective-C:Swift:
4.3 Prepare information about devices
Different from other types of Tuya-enabled devices, certain information about Matter devices must be prepared in advance. For this purpose, at the end of loading home information and fabric information, call – getDevicesFabricNodesWithdevIds :callback: to handle Matter devices for the specified home.
API descriptionParameters
Parameter | Description |
devIds | The list of device IDs. |
Example
Objective-C:Swift:
Documents / Resources
![]() |
tuya Prepare for Integration with Matter Device [pdf] User Guide Prepare for Integration with Matter Device, Integration with Matter Device, Matter Device |