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. Fast Integration With Cube App SDK Fori OS

Fast Integration with Cube App SDK for iOS

Last Updated on: 2024-09-25 12:53:28

This topic describes how to use CocoaPods to quickly integrate Tuya Cube App SDK for iOS into your project. The SDK requires iOS 9.0 or later.

SDK versions

  • If you have integrated Cube App SDK versions earlier than v5.x.x into your project, follow the instructions in Upgrade Guide and upgrade to the latest version.
  • If you have integrated legacy SDK versions into your project, after you upgrade to v5.0, delete the legacy security image file t_s.bmp from your project, and get the app key information for v5.0 from the Tuya Developer Platform.

Integrate with the SDK

Build and download the SDK
  1. Log in to the Tuya Developer Platform.

  2. Select the required SDKs or UI BizBundles of v5.x.x.

    Note

    If a legacy SDK version has been used, you can click the button in the top right corner to switch between the legacy and new versions.

    Fast Integration with Cube App SDK for iOS
  3. Select the required SDKs or BizBundles and build your SDK.

    Fast Integration with Cube App SDK for iOS
  4. After the build is finished, download the SDK to be integrated.

    Fast Integration with Cube App SDK for iOS
  5. Extract ios_core_sdk.tar.gz and get the following important files:

    • Build: stores the security SDK exclusive to your app. This file is as important as the app key information. Keep the file properly and do not disclose the information in it.
    • ThingSmartCryption.podspec: used to reference and integrate with App SDK v5.0.
  6. We recommend that you store both files at a sibling directory as podfile, so they can be referenced easily during subsequent development.

Use CocoaPods for fast integration
  1. Update CocoaPods to the latest version. For more information about CocoaPods, see CocoaPods Guides.

  2. Add the following code block to the Podfile:

    source 'https://github.com/tuya/tuya-private-specs.git'
    platform :ios, '11.0'
    
    target 'Your_Project_Name' do
        # Build and get ThingSmartCryption from the Tuya Developer Platform.
        # After the official edition is purchased, rebuild the SDK on the Tuya Developer Platform and integrate it into your project.
        # The dot slash (./) notation represents that the files that are obtained after ios_core_sdk.tar.gz is extracted are put at a sibling directory as podfile.
        # To use another directory, change the path to your desired directory.
        pod "ThingSmartCryption", :path =>'./'
        pod "ThingSmartHomeKit"
    end
    
    target 'Your_Extension_Target_Name' do
        # Regarding all extension targets, as long as ThingSmartHomeKit is imported, ThingSmartCryption must be imported too.
        pod "ThingSmartCryption", :path =>'./'
        pod "ThingSmartHomeKit"
    end
  3. If your app contains extension targets, such as Siri and Widgets, make sure the Podfile is configured correctly.

  4. In the root directory of your project, run pod update.

Use configuration file for iOS
  1. Import the domain configuration file.

    1. Download ThingSmartCryption.xcframework from the platform and place it in the project directory.

    2. Replace the t_cdc.tcfg files in the following folders with the t_cdc.tcfg files provided by PM.

    3. Run pod install or pod update to install or update dependencies accordingly.

      Fast Integration with Cube App SDK for iOS
  2. Verify the validity of the custom domain name.

    Note

    Before this step, the steps in Fast Integration with Smart Life App SDK must be finished.

    You can use this setting [TuyaSmartSDK sharedInstance].debugMode = YES to enable the SDK debug log feature. After the app starts, search for the log entry read custom domain config in the console to check whether data can be read out from the domain configuration file.

    If so, disable the SDK debug log feature, repackage the app, and then upload the package to Apple’s App Store to launch the app.

Initialize the SDK
  1. Choose Target > General to open the project settings, and modify Bundle Identifier to the iOS Bundle ID of the app that is registered on the Tuya Developer Platform.

  2. Add the following content to the PrefixHeader.pch file:

    #import <ThingSmartHomeKit/ThingSmartKit.h>

    Add the following content to the bridging header file xxx_Bridging-Header.h for a Swift project:

    #import <ThingSmartHomeKit/ThingSmartKit.h>
  3. Open the AppDelegate.m file and initialize the SDK in [AppDelegate application:didFinishLaunchingWithOptions:].

Configure the SDK
- (void)startWithAppKey:(NSString *)appKey secretKey:(NSString *)secretKey;

Parameters

Parameter Description Source
appKey The credential information exclusive to the app. Platform > Details page of your SDK-based app > Get SDK
secretKey The secret key of the app. Platform > Details page of your SDK-based app > Get SDK
bundleId The Bundle ID for iOS. Platform > Details page of your SDK-based app > Bundle ID for iOS

Sample code

Objective-C:

[[ThingSmartSDK sharedInstance] startWithAppKey:<#your_app_key#> secretKey:<#your_secret_key#>];

Swift:

ThingSmartSDK.sharedInstance()?.start(withAppKey: <#your_app_key#>, secretKey: <#your_secret_key#>)

Now, you are ready for app development.

Enable the debug mode

During the development, you can enable the debug mode and print logs for troubleshooting.

Objective-C:

#ifdef DEBUG
    [[ThingSmartSDK sharedInstance] setDebugMode:YES];
#else
#endif

Swift:

#if DEBUG
   ThingSmartSDK.sharedInstance()?.debugMode = true
#else
#endif
Configure multilingual options

The returned error messages and other UI text are displayed in languages as configured in the multilingual settings of your project and users’ mobile phone system languages. To support a certain language, add it to Localization of your project.

In the following example, a demo app is used to describe the process of app development with the App SDK. Before the development of your app, we recommend that you run the demo app.

Create a widget

Perform the following steps:

  1. Modify the Podfile.

    target 'Your_Extension_Target_Name' do
        # 1. Regarding all extension targets, as long as ThingSmartHomeKit is imported, ThingSmartCryption must be imported too.
        # 2. Build and get ThingSmartCryption from the Tuya Developer Platform.
        # After the official edition is purchased, rebuild the SDK on the Tuya Developer Platform and integrate it into your project.
        # The dot slash (./) notation represents that the files that are obtained after ios_core_sdk.tar.gz is extracted are put at a sibling directory as podfile.
        # To use another directory, change the path to your desired directory.
        pod "ThingSmartCryption", :path =>'./'
        pod "ThingSmartHomeKit"
    end
    
    post_install do | installer |
         installer.pods_project.targets.each do | target |
            target.build_configurations.each do | config |
                config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
            end
        end
    end
    • Configure Target and import components or SDKs into Target as needed.
    • Note that ThingSmartCryption must be imported together with the SDK.
  2. Configure AppGroups.

    • Grant permissions on AppGroups.
    • Before the SDK is initialized, set the App Groups Name for the SDK.
    • Only paid developer accounts can be granted permissions on AppGroups. Therefore, free developer accounts cannot be used to debug widget applications.
  3. Configure the AppKey and AppSecret to initialize the SDK.

  4. Before the SDK is initialized with AppKey, set the App Groups Name.

    [ThingSmartSDK sharedInstance].appGroupId = APP_GROUP_NAME;
    [[ThingSmartSDK sharedInstance] startWithAppKey:SDK_APPKEY secretKey:SDK_APPSECRET];

Demo app

Important

The demo app that is created in the sample project of Cube App SDK is used for reference only. Do not use the demo app for commercial purposes. For more information, see Tuya Development Service Agreement.

Prepare the demo

In the Preparation topic, get the AppKey and AppSecret for iOS.

Make sure that BundleId, AppKey, and AppSecret are consistent with those used on the Tuya Developer Platform. Any mismatch will cause the SDK development app to fail.

Important

If the SDK is switched from v5.0 to another version, you must change the key information to that of the target version. The way the SDK is integrated is changed accordingly.

Demo features

The demo app is coded in Swift and Objective-C. You can get the sample in Objective-C on GitHub. The following features are supported:

  • User registration and login

  • User management

  • Home management

  • Wi-Fi Easy Connect (EZ) mode and access point (AP) mode

  • Device Control

    Fast Integration with Cube App SDK for iOS

FAQs

SING_VALIDATE_FALED
  • Problem: When an API request is made, an error message is returned in the following response:

    {
      "success" : false,
      "errorCode" : "SING_VALIDATE_FALED",
      "status" : "error",
      "errorMsg" : "Permission Verification Failed",
      "t" : 1583208740059
    }
  • Solution: Make sure that BundleId, AppKey, and AppSecret are consistent with those used on the Tuya Developer Platform. Any mismatch will cause the authentication to fail. For more information, see Preparation.

  • Prev Doc Developer Guide for iOS
  • Next Doc Upgrade Guide
This page contains content