Is this page helpful?
YesNoLast 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.
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.
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.
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.
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>
Open the AppDelegate.m
file and call the method [AppDelegate application:didFinishLaunchingWithOptions:]
to initialize 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.
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
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.
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.
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:
Demo app
pod update
.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.
Is this page helpful?
YesNoIs this page helpful?
YesNo