tuya Prepare for Integration with Matter Device User Guide

June 17, 2024
Tuya

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

Configure and integrate with main project

2.1 Configure entitlements

  1. Open the project settings in Xcode.
  2. Choose the target of the main project> Signing& Capabilities, and click + Capability.tuya Prepare for Integration with Matter Device - paers
  3. Add the entitlement Matter Allow Setup Payload that is used to handle parsing of Matter QR codes.
  4. 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.
  5. 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.

tuya Prepare for Integration with Matter Device -
parts 2.2 Configure Info.plist

  1. Open the project settings in Xcode.
  2. Choose the target of the main project> Info> Custom iOS Target Prop- erties.

tuya Prepare for Integration with Matter Device -
parts1

  • 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:

tuya Prepare for Integration with Matter Device -
parts2 2.3 Use CocoaPods for fast integration

  1. We recommend that you update CocoaPods to the latest version.
  2. Add the following code block to the Podfile:tuya Prepare for Integration with Matter Device - parts3
  3. 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.tuya Prepare for Integration with Matter Device -
parts4 API descriptiontuya Prepare
for Integration with Matter Device - parts5 Parameters

Parameter Description
configKey The App Group ID of the project.

Example
Objective-C:tuya Prepare for Integration with Matter Device -
parts6 Swift:tuya Prepare for
Integration with Matter Device - parts7

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

  1. Open the project settings in Xcode.
  2. Choose the target of the main project> Signing& Capabilities, and click + Capability.
  3. 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

  1. We recommend that you update CocoaPods to the latest version.
  2. Add the following code block to the Podfile:tuya Prepare for Integration with Matter Device - parts8
  3. 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.tuya Prepare for Integration with Matter Device -
parts9 API description

tuya Prepare for Integration with Matter Device -
parts10 Parameters

Parameter Description
configKey The App Group ID of the project.

Example
Swift:tuya Prepare for Integration with Matter Device -
parts11 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.

  1. Import ThingSmartMatterExtensionKit into the project.tuya Prepare for Integration with Matter Device - parts12
  2. 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.

tuya Prepare for Integration with Matter Device -
parts13

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.tuya Prepare for Integration with Matter Device -
parts14 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 descriptiontuya Prepare for Integration with Matter Device -
parts15 Parameters

Parameter Description
spaceId The value of HomeID for the current home.
success The success callback.
failure The failure callback.

Example
Objective-C:tuya Prepare for Integration with Matter Device -
parts16 Swift:tuya Prepare for
Integration with Matter Device - parts17 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 descriptiontuya Prepare for Integration with Matter Device -
parts18 Parameters

Parameter Description
devIds The list of device IDs.

Example
Objective-C:tuya Prepare for Integration with Matter Device -
parts19 Swift:tuya Prepare for
Integration with Matter Device - parts20

Documents / Resources

| tuya Prepare for Integration with Matter Device [pdf] User Guide
Prepare for Integration with Matter Device, Integration with Matter Device, Matter Device
---|---

References

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

Related Manuals