Copied!
Private Cloud
  • Application Development Services
    • Quick Start
    • API Gateway
      • API Request
        • Request Structure
        • Authorization Method
        • Sign Requests
        • Global Error Codes
      • Best Practice
        • Set Postman Environment and Call API Operations
      • API List
        • Basic API
          • Authorization Token Management
            • Refresh Token
            • Get a Token
        • IoT Core
          • Device Management
            • Query Devices in Space
            • Get Status Reporting Log
            • Get Update Progress
            • Query Device Details in Bulk
            • Delete Device
            • Get Update Information
            • Query Device Details
            • Confirm Start of Update
            • Get Device State
            • Get Operation Log
            • Modify Basic Properties
            • Freeze/Unfreeze Device
            • Transfer Device
            • Restore Factory Defaults
            • Query Pairing Result
          • Device Control
            • Send Property
            • Query Properties
            • Modify Properties
            • Set Desired Property
            • Query Desired Properties
            • Query Things Data Model
            • Device Control (Standard Instruction Set)
              • Get Status Set
              • Send Commands
              • Get Specifications and Properties of the Device
              • Get Instruction Set of the Device
              • Get Instruction Set of the Category
              • Get Status of a Single Device
              • Get Latest Status of Multiple Devices
          • Device Group
            • Create Group
            • Delete Group
            • Query Group
            • Rename Group
            • Get Group in Space
            • Add Device
            • Delete Devices
            • Get Device Group
            • Query Group Properties
            • Send Group Properties
            • Query Group Devices
    • Message Gateway
      • Preparations
      • Development Guide
        • Integrate with Message Service
        • Data Signature
        • Message Types
      • Best Practices
        • Get Push Messages by Pulsar (Java SDK)
        • Get Push Messages by Pulsar (Python SDK)
        • Get Push Messages by Pulsar (Go SDK)
        • Get Push Messages by Pulsar (Node.js SDK)
        • Get Push Messages by Pulsar (C# SDK)
  • App Development
    • Preparation
    • Developer Guide for iOS
      • Fast Integration with Cube App SDK for iOS
      • Upgrade Guide
      • Quick Start with Cube App SDK for iOS
      • iOS App: Implement User Account Features
      • User Account Management (iOS)
        • Register and Login with Phone Number
        • Register and Login with Email Address
        • Login with UID
        • Login with Third-Party Account
        • Register and Login with Anonymous Account
        • QR Code-Based Login Authorization
        • Manage User Accounts
      • Home Management
        • Home Information Management
        • Room Information Management
        • Member Information Management
      • Device Pairing (iOS)
        • Wi-Fi EZ Mode
        • AP Mode
        • Wired Mode
        • Sub-Device Pairing
        • NB-IoT Device Pairing
        • HomeKit Device Pairing
        • Pegasus Pairing
        • CPPLUS Link-Based Device Binding
        • Matter Devices
          • Prepare for Integration with Matter Device
          • Pair Matter Device
        • Pair with QR Code on Device
      • Bluetooth Devices
        • Bluetooth Mesh
        • CPPLUS Mesh
      • Device Management
        • Firmware Update
        • Query Reported DP Logs
        • Device Sharing
        • Backup Wi-Fi Networks
        • Offline Device Alerts
        • CPPLUS Link-Based Devices
        • Manage Matter Devices
      • Device Control
        • Multi-Control Linkage
        • Scheduled Tasks
        • Group Management
        • All Category Control Panel
        • Air Conditioning Category Control Panel
        • Switch Control Panel
        • Device DP Parser
      • Smart Scenes
        • Scene Recommendation
      • Common API Methods
      • Integrate with Push Notifications
      • Message Management
        • Configure Push Notifications
        • Message Capabilities
      • Configure Widget Project
      • Error Codes
      • FAQ
      • Extension SDK
        • IPC SDK
          • SDK Architecture
          • Fast Integration with IPC SDK for iOS
          • Quick Start with IPC SDK for iOS
          • IPCs
          • Device Pairing
          • IPC Control (iOS)
          • Live Video Streaming
          • Playback of Video Stored on SD Card
          • SD Card Management
          • Audio and Video Features
          • Low Power Doorbell
          • PTZ Control
          • Doorbell Call Service
          • Cloud Storage
          • Cloud Storage Debugging Tool
          • Detection Alerts
          • Encrypted Images
          • Timeline View
          • Offline Log
          • Migrate IPC UI BizBundles
          • P2P Capabilities
          • IPC SDK Automated Test Tool
          • IPC SDK Test Cases (Reference)
          • FAQ
          • Error Codes
        • Sweeper SDK
          • P2P Download from Robot Vacuums
          • Gyroscope and Visual Robot Vacuums
          • Laser Robot Vacuum
          • Voice Package Download
          • Error Codes
          • Sample Code
        • Smart Lock SDK
          • Wi-Fi Lock
          • Bluetooth Lock
          • Wi-Fi Lock Audio and Video Capability
          • Smart Lock Basic API
      • What is UI BizBundle SDK for iOS?
        • Preparation
        • Integrate with Framework
        • Home Management UI BizBundle
        • Device Pairing UI BizBundle
        • Scene UI BizBundle
        • Multi-Control Linkage UI BizBundle
        • Device Control UI BizBundle
        • OTA UI BizBundle
        • Group Management UI BizBundle
        • Device Details UI BizBundle
        • Panel Multilingual BizBundle
        • IPC UI BizBundles
        • Cloud Storage UI BizBundle
        • FAQ UI BizBundle
        • Message Center UI BizBundle
        • Voice Skills Account Linking UI BizBundle
        • Theme Color Configuration BizBundle
        • Sharing UI BizBundle
      • Changelog
    • Developer Guide for Android
      • Fast Integration with Cube App SDK for Android
      • Upgrade Guide
      • User Account Management
        • Register and Login with Phone Number
        • Register and Login with Email Address
        • Login with UID
        • Login with Third-Party Account
        • Register and Login with Anonymous Account
        • QR Code-Based Login Authorization
        • Manage User Accounts
      • Home Management
        • Home Information Management
        • Room Information Management
        • Member Information Management
      • Device Pairing (iOS)
        • Wi-Fi EZ Mode
        • AP Mode
        • Wired Mode
        • Pair with QR Code on Device
        • Pegasus Pairing
        • Sub-Device Pairing
        • NB-IoT Device Pairing
        • CPPLUS Link-Based Device Binding
        • Matter Devices
          • Prepare for Integration with Matter Device
          • Pair Matter Device
        • Pair with QR Code on Device
      • Bluetooth Devices
        • Bluetooth LE Devices
        • Bluetooth Mesh
        • CPPLUS Mesh
      • Device Management
        • Firmware Update
        • Query Reported DP Logs
        • Device Sharing
        • Backup Wi-Fi Networks
        • Notifications of Devices Getting Offline
        • CPPLUS Link-Based Devices
        • Manage Matter Devices
      • Device Control
        • Sub-Device Control Through Zigbee Gateway
        • Multi-Control Linkage
        • Scheduled Tasks
        • Group Management
        • Device DP Parser
      • Smart Scenes
        • Scene Recommendation
      • Common API Methods
      • Integrate with Push Notifications
        • Integrate with FCM Push
        • Integrate with Xiaomi Push Notifications
        • Integrate with Huawei Push Notifications
      • Message Management
        • Configure Push Notifications
        • Message Capabilities
      • Error Codes
      • FAQ
      • Extension SDK
        • IPC SDK
          • IPC SDK Architecture
          • Fast Integration with IPC SDK for Android
          • IPCs
          • Device Pairing
          • Live Video Streaming
          • SD Card-Stored Video Playback
          • SD Card Management
          • Audio and Video Features
          • Cloud Storage
          • Cloud Storage Debugging Tool
          • Alert List
          • Video Alerts
          • Low Power Doorbell
          • Encrypted Images
          • Timeline View
          • P2P Capabilities
          • IPC SDK Automated Test Tool
          • IPC SDK Test Cases (Reference)
          • Error Codes
          • SDK Log
          • Changelog
        • Sweeper SDK
          • P2P Download from Robot Vacuums
          • Gyroscope and Visual Robot Vacuums
          • Laser Robot Vacuum
          • Voice Package Download
          • Changelog
          • Error Codes
          • Sample Code
        • Smart Lock SDK
          • Wi-Fi Smart Lock
          • Bluetooth Smart Lock
          • Wi-Fi Smart Lock Audio and Video Capabilities
          • Zigbee Lock
          • Smart Lock Basic API
          • Changelog
      • What is UI BizBundle SDK for iOS?
        • Preparation
        • Integrate with Framework
        • Home Management UI BizBundle
        • Device Pairing UI BizBundle
        • Generic Pairing BizBundle
        • Device Control UI BizBundle
        • Multi-Control Linkage UI BizBundle
        • Scene UI BizBundle
        • Group Management UI BizBundle
        • Device Details UI BizBundle
        • OTA UI BizBundle
        • IPC UI BizBundles
        • Cloud Storage UI BizBundle
        • Message Center UI BizBundle
        • FAQ UI BizBundle
        • Maps Service UI BizBundle
        • Voice Skills Account Linking UI BizBundle
        • Panel Multilingual BizBundle
        • Theme Color Configuration BizBundle
        • Sharing UI BizBundle
        • FAQ
      • Changelog
  1. Home
  2. App Development
  3. I OS
  4. Prepare For Integration With Matter Device

Prepare for Integration with Matter Device

Last Updated on: 2024-06-07 07:31:26

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 third-party Matter device, add an extension target to your Xcode project.

Prerequisites

  • Before you start, the steps in Fast Integration with Cube App SDK must be finished.

  • If you require UI BizBundles, the version of Cube 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

Configure entitlements
  1. Open the project settings in Xcode.

  2. Choose the target of the main project > Signing & Capabilities, and click + Capability.

    Prepare for Integration with Matter Device
  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.

    Prepare for Integration with Matter Device
Configure Info.plist
  1. Open the project settings in Xcode.

  2. Choose the target of the main project > Info > Custom iOS Target Properties.

    Prepare for Integration with Matter Device
    • 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:

      <key>NSBonjourServices</key>
          <array>
              <string>_meshcop._udp</string>
              <string>_matter._tcp</string>
              <string>_matterc._udp</string>
              <string>_matterd._udp</string>
          </array>
      
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:

    platform :ios, '9.0'
    
    target 'Your_Project_Name' do
        pod "ThingSmartMatterKit"
    end
    
  3. In the root directory of your project, run pod update.

    For more information about CocoaPods, see CocoaPods Guides.

Initialize module

Follow the instructions in Fast Integration with Cube App SDK for iOS and initialize the SDK. Then, initialize the Matter module.

// Initialize the SDK.
[[ThingSmartSDK sharedInstance] startWithAppKey:<#your_app_key#> secretKey:<#your_secret_key#>];

// Initialize the Matter module.
[ThingSmartMatterActivatorConfig setMatterConfigKey:<#YOUR_APP_GROUP_ID#>];

API description

+ (void)setMatterConfigKey:(NSString *)configKey;

Parameters

Parameter Description
configKey The App Group ID of the project.

Example

Objc:

[ThingSmartMatterActivatorConfig setMatterConfigKey:<#YOUR_APP_GROUP_ID#>];

Swift:

ThingSmartMatterActivatorConfig.setMatterKey("YOUR_APP_GROUP_ID")

Configure and integrate with Extension Target

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

    platform :ios, '9.0'
    
    target 'Your_Matter_Extension_Target_Name' do
        pod "ThingSmartMatterExtensionKit"
    end
  3. In the root directory of your project, run pod update.

    For more information about CocoaPods, see CocoaPods Guides.

Initialize module

Open the file RequestHandler.swift in the ExtensionTarget project and rewrite the init method.

override init()

API description

+ (void)setMatterConfigKey:(NSString *)configKey;

Parameters

Parameter Description
configKey The App Group ID of the project.

Example

Swift:

override init() {
  super.init()
  ThingMatterExtensionSupport.shared.setMatterConfigKey(configKey: <#YOUR_APP_GROUP_ID#>)
}
Use ThingSmartMatterExtensionKit

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.

    import ThingSmartMatterExtensionKit
  2. Make API requests with the methods that are automatically generated by the system, as shown in the following code block.

    Important

    The callback methods in RequestHandler.swift are automatically generated by the system and cannot be modified.

        override func validateDeviceCredential(_ deviceCredential: MatterAddDeviceExtensionRequestHandler.DeviceCredential) async throws {
            ThingMatterExtensionSupport.shared.validateDeviceCredential(deviceCredential)
        }
    
        override func selectWi-FiNetwork(from wifiScanResults: [MatterAddDeviceExtensionRequestHandler.Wi-FiScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.Wi-FiNetworkAssociation {
            // Use this function to select a Wi-Fi network for the device if your ecosystem has special requirements.
            // Or, return .defaultSystemNetwork to use the iOS device's current network.
            return ThingMatterExtensionSupport.shared.selectWi-FiNetwork(from: wifiScanResults)
        }
    
        override func selectThreadNetwork(from threadScanResults: [MatterAddDeviceExtensionRequestHandler.ThreadScanResult]) async throws -> MatterAddDeviceExtensionRequestHandler.ThreadNetworkAssociation {
            // Use this function to select a Thread network for the device if your ecosystem has special requirements.
            // Or, return .defaultSystemNetwork to use the default Thread network.
            return ThingMatterExtensionSupport.shared.selectThreadNetwork(from: threadScanResults)
        }
    
        override func commissionDevice(in home: MatterAddDeviceRequest.Home?, onboardingPayload: String, commissioningID: UUID) async throws {
            // Use this function to commission the device with your Matter stack.
            ThingMatterExtensionSupport.shared.commissionDevice(in: home, onboardingPayload: onboardingPayload, commissioningID: commissioningID)
        }
    
        override func rooms(in home: MatterAddDeviceRequest.Home?) async -> [MatterAddDeviceRequest.Room] {
            // Use this function to return the rooms your ecosystem manages.
            // If your ecosystem manages multiple homes, ensure you are returning rooms that belong to the provided home.
            return ThingMatterExtensionSupport.shared.rooms(in: home)
        }
    
        override func configureDevice(named name: String, in room: MatterAddDeviceRequest.Room?) async {
            // Use this function to configure the (now) commissioned device with the given name and room.
            ThingMatterExtensionSupport.shared.configureDevice(named: name, in: room)
        }

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.

Note

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.

Sequence diagram

The following figure shows the sequence in which basic Matter information is configured.

UserAppSDKInitially load home or switch between homesLoad information about homeReturn information about homeRequest loading list of devicesReturn list of devicesHandle Matter capabilitiesPrepare information about fabricFabric information loadedPrepare information about devicesDevice information preparedUse Matter capabilitiesUserAppSDK
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 description

@interface ThingSmartMatterManager : NSObject
+ (instancetype)sharedInstance;
- (void)loadFabricWithSpaceId:(long long)spaceId
                success:(ThingSuccessHandler)success
                      failure:(ThingFailureError)failure;
@end

Parameters

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

Example

Objc:

- (void)loadMatterCurrentHomeFabric:(long long)homeId {
    // Called at the end of the operation of switching between homes or initially loading a home.
    [[ThingSmartMatterManager sharedInstance] loadFabricWithSpaceId:homeId success:^{
        NSLog(@"load fabric success");
    } failure:^(NSError *error) {
        NSLog(@"load fabric fail");
    }];
}

Swift:

func loadMatterCurrentHomeFabric(homeId: Int64) {
    // Called at the end of the operation of switching between homes or initially loading a home.
    ThingSmartMatterManager.sharedInstance().loadFabric(withSpaceId: homeId) {
        print("load fabric success")
    } failure: { error in
        print("load fabric fail")
    }
}
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 description

@interface ThingSmartMatterShareManager : NSObject
+ (instancetype)sharedInstance;
- (void)getDevicesFabricNodesWithdevIds:(NSArray <NSString *>*)devIds callback:(void(^)(NSArray <ThingSmartMatterDeviceNodeModel *>*result))callback;
@end

Parameters

Parameter Description
devIds The list of device IDs.

Example

Objective-C:

- (void)loadMatterDeviceInfo {
    // Called at the end of - loadFabric and loading devices in the home.
    [[ThingSmartMatterShareManager sharedInstance] getDevicesFabricNodesWithdevIds:deviceIdList callback:^(NSArray<ThingSmartMatterDeviceNodeModel *> *result) {
        NSLog(@"load matter device node succes");
    }];
}

Swift:

func loadMatterDeviceInfo(){
  // Called at the end of - loadFabric and loading devices in the home.
  ThingSmartMatterShareManager.sharedInstance().getDevicesFabricNodesWithdevIds(deviceIdList) { modelList in
      print("load matter device info success")
  }
}
  • Prev Doc Matter Devices
  • Next Doc Pair Matter Device
This page contains content