English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Fast Integration with Commercial Lighting App SDK for iOS

Last Updated on : 2022-02-17 05:18:08download

This topic describes how to use CocoaPods to quickly integrate the Commercial Lighting App SDK for iOS into your project. The Commercial Lighting App SDK requires iOS version 10.0.

Integrate the SDK

Use CocoaPods for integration

We recommend that you update CocoaPods to the latest version and add the following code block to the Podfile file.

platform :ios, '10.0'

target 'Your_Project_Name' do
	pod "TuyaCommercialLightingKit"
end

Run the pod update command in the root directory of your project to integrate the SDK.

For more information about CocoaPods, see CocoaPods Guides.

Initialize the SDK

  1. Open the project settings page, choose Target > General, and then change Bundle Identifier to the iOS package name that is used on the Tuya IoT Platform.

  2. Import the security image to the root directory of your project, rename it as t_s.bmp, and then add it to the directory Project Settings > Target > Build Phases > Copy Bundle Resources.
    Fast Integration with Commercial Lighting App SDK for iOS
    Fast Integration with Commercial Lighting App SDK for iOS

  3. Add the following content to the PrefixHeader.pch file of your project.

    #import <TuyaCommercialLightingKit/TuyaCommercialLightingKit.h>
    

    For Swift projects, you can add the following content to the xxx_Bridging-Header.h bridge file.

    #import <TuyaCommercialLightingKit/TuyaCommercialLightingKit.h>
    
  4. Open the AppDelegate.m file and call the method [AppDelegate application:didFinishLaunchingWithOptions:] to initialize the SDK.

Configure the SDK

- (void)startWithAppKey:(NSString *)appKey secretKey:(NSString *)secretKey;

Parameters

parameter Description
appKey AppKey
secretKey AppSecret

Example

Objc:

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

Swift:

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

Now, all preparation steps are finished.

Enable the debug mode

The debug mode can be enabled during the development to print logs for troubleshooting.

Objc:

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

Swift:

#if DEBUG
   TuyaSmartSDK.sharedInstance()? .debugMode = true
#else
#endif

Multilingual settings

The error messages and other text returned by the interfaces are displayed based on the multilingual settings of your project and users’ mobile phones.

To support a specific language, you can add the language to Localization in your project.

In this topic, 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.

Run the demo app

Prepare the demo app

After you integrate the SDK, you can get the security image, AppKey, and AppSecret that are obtained in Preparation. Make sure the security image, BundleId, AppKey, and AppSecret are consistent with those used on the Tuya IoT Platform. Any mismatch will cause the SDK development to be failed.

Demo app description

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:

  • Log in and register
  • Manage projects
  • Manage areas
  • Manage groups
  • Control devices
  • Manage energy consumption
  • Maintain devices

Demo app

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

Run the demo

  1. Make sure you have initialized the SDK.
  2. Go to the demo directory and run pod update.

Troubleshoot the error message: Permission Verification Failed

  • Problem: When the system runs the demo app, an error message is returned in the following response.

    {
      "success" : false,
      "errorCode" : "SING_VALIDATE_FALED",
      "status" : "error",
      "errorMsg" : "Permission Verification Failed",
      "t" : 1583208740059
    }
    
  • Solution: Check whether your security image, BundleId, AppKey, and AppSecret match the information on the Tuya IoT Platform. For more information, see Preparation.