Fast Integration with Commercial Lighting App SDK for iOS

Last Updated on : 2024-06-12 10:22:48download

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

SDK versions

Commercial Lighting App SDK is classified into the development edition and official edition.

  • The development edition is suitable for personal non-commercial scenarios only. Do not use it for commercial purposes. If your app is planned to be launched on app stores or in other commercial scenarios, go to the Tuya IoT Development Platform and purchase the official edition.

  • After the official edition is purchased:

    1. Rebuild the SDK and download the package of the official edition on the platform.
    2. Integrate the SDK of the official edition into your project.

Integrate with the SDK

Build and download the SDK

  1. Log in to the Tuya IoT Development Platform.

  2. Select the required SDKs or UI BizBundles.

    Fast Integration with Commercial Lighting App SDK for iOS
  3. Build your SDK.

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

    Fast Integration with Commercial Lighting 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-pod-specs.git'
    platform :ios, '11.0'
    
    target 'Your_Project_Name' do
        # Build and get ThingSmartCryption from the Tuya IoT Development Platform (iot.tuya.com).
        # After the official edition is purchased, rebuild the SDK on the Tuya IoT Development 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 "ThingCommercialLightingKit"
    end
    
  3. In the root directory of your project, run pod update.

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 IoT Development Platform.

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

    #import <ThingCommercialLightingKit/ThingCommercialLightingKit.h>
    

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

    #import <ThingCommercialLightingKit/ThingCommercialLightingKit.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. Go to App SDKs on the Tuya IoT Development Platform, click the target SDK-based app, and click Get Key
secretKey The secret key of the app. Go to App SDKs on the Tuya IoT Development Platform, click the target SDK-based app, and click Get Key
bundleId The Bundle ID for iOS. Go to App SDKs on the Tuya IoT Development Platform, click the target SDK-based app, and view the 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.

Demo app

The demo app that is created in the sample project of Commercial Lighting App SDK is used for reference only. Do not use the demo app for commercial purposes. For more information, see Tuya Developing 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 IoT Development Platform. Any mismatch will cause the SDK development app to fail.

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

In the demo project, a version of Objective-C is used. To get the demo project, see Sample for Objective-C. The project supports the following features:

  • Register and log in

  • Manage projects

    • View a list of projects
    • Create a project
  • View a list of spaces

    • Control devices in spaces
    • Create a sub-space
    • Delete a space
  • View a list of devices

  • View a list of groups

    • Create a group
    • Control a group
  • UI BizBundles

    • Device Control UI BizBundle
    • Device Pairing UI BizBundle

    Fast Integration with Commercial Lighting App SDK for iOS Fast Integration with Commercial Lighting App SDK for iOS Fast Integration with Commercial Lighting 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 IoT Development Platform. Any mismatch will cause the authentication to fail. For more information, see Preparation.

  • Note: After you purchase the official edition, rebuild the SDK and replace the key information with the new one on the Tuya IoT Development Platform.