Fast Integration

Last Updated on : 2024-05-28 03:08:51download

This topic describes how to quickly integrate the Smart Industry App SDK for iOS into your development environment, such as Xcode. It also sheds light on the initialization method and how to enable the debugging mode with a few simple steps. This allows you to run the demo app and get started with your smart industry app development.

Prerequisites

  • You have created a developer account and downloaded the SDK. For more information, see Preparation.
  • The following software is installed:
    • Xcode 14.0 or later
    • CocoaPods 1.10.0 or later
  • Your project must be targeted to iOS 10.0 or later.

Integrate with the SDK

Each app is provided with a unique and secure SDK. This topic describes how to integrate the SDK v2.2.0 into your project using CocoaPods.

Step 1: Get important files

On the SDK Development page, click the target SDK to show the Get SDK tab.

Fast Integration

After extracting the downloaded ios_core_sdk.tar.gz, you will get three important files:

  • Build: The secure SDK specific to your app. It is as important as the app key, so be sure to keep it safe.
  • ThingSmartCryption.podspec: Used to import and integrate the SDK v2.2.0.
  • domain.txt: The domain for making requests, including six data centers.

It is recommended to store the Build and ThingSmartCryption.podspec folders in the same directory as the podfile to facilitate reference and operation later.

Step 2: Update Podfile

Declare the following in the podfile:

    # Build and get the ThingSmartCryption from platform.tuya.com.
    # After purchasing the official edition, rebuild the SDK on the Developer Platform and integrate it into your project again.
    # ./ indicates that you extract 'ios_core_sdk.tar.gz' to the same directory as the podfile.
    # To save the extracted file to a different location, adjust the path as needed.

    pod 'ThingSmartCryption', :path => './'

The podfile downloaded from the Tuya Developer Platform already declares the feature SDK you selected. You can get the reference declarations for other feature SDKs from the podfile.

Step 3: Integrate the SDK

Executing $ pod update will automatically integrate the downloaded SDK into your iOS project.

Step 4: Configure app information

Bundle ID

Open the project settings on Xcode, choose Target > General, and then modify Bundle Identifier to the iOS Bundle ID set on the Tuya Developer Platform.

Key

On the SDK Development page, click the target SDK and then the Get Key tab.

Fast Integration

Cloud project overview

The projectCode information is required for user login. On the Cloud Development page, click Open Project in the Operation column to show the project Overview.

Fast Integration

App authorization information

Client ID and Client Secret are required to initialize the SDK.

  1. On the Cloud Development page, click Open Project in the Operation column.

  2. Choose Authorization > App Authorization.

    Fast Integration

Step 5: Initialize the SDK

Objective-C:

// init url
[IndustryLinkSDK setHost:<#your_app_host#>];

// IndustryLinkSDK
[IndustryLinkSDK initializeWithAppKey:<#your_app_key#>
                            appSecret:<#your_app_secret_key#>
                             clientId:<#your_clientId#>
                         clientSecret:<#your_client_secret#>];

[MQTTBusinessPlugin initializePlugin];

Swift:

// init url
IndustryLinkSDK.host = <#your_app_host#>

// IndustryLinkSDK
IndustryLinkSDK.initialize(withAppKey: <#your_app_key#>,
                            appSecret: <#your_app_secret_key#>,
                            clientId: <#your_clientId#>,
                            clientSecret: <#your_client_secret#>)

// If need mqtt
MQTTBusinessPlugin.initializePlugin()

When integrating with the SDK, make sure the BundleId, AppKey, AppSecret, clientID, and clientSecret are consistent with those used on the Tuya Developer Platform. Any mismatch will cause the SDK development to fail.

The request host must match the data center of the cloud project, because data from different data centers is isolated.

  • AY: China Data Center
  • EU: Central Europe Data Center
  • AZ: Western America Data Center
  • WE: Western Europe Data Center
  • UE: Eastern America Data Center
  • IN: India Data Center

Things to note

The SDK development edition is for development purposes only and should not be used commercially. To publish your app on app stores, purchase the official edition.

After you purchase the official edition:

  1. Rebuild and download the SDK of the official edition on the Tuya Developer Platform.
  2. Integrate this SDK into your project.

For more information, see Tuya Developing Service Agreement.