Last Updated on : 2022-07-20 10:52:36download
This topic describes how to use CocoaPods to quickly integrate Tuya Commercial Lighting App SDK for iOS into your project. The SDK requires iOS 10.0 or later.
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
In the root directory of your project, run pod update
.
For more information about CocoaPods, see CocoaPods Guides.
Open the project settings, click Target > General, and then modify Bundle Identifier
to the iOS Bundle ID set on the Tuya IoT Development Platform.
Import the security image to the root directory of the project, and rename it as t_s.bmp
. Go to Project Settings > Target > Build Phases, and add this image to Copy Bundle Resources.
Add the following content to the project file PrefixHeader.pch
:
#import <TuyaCommercialLightingKit/TuyaCommercialLightingKit.h>
For a Swift project, add the following content to the bridging header file xxx_Bridging-Header.h
:
#import <TuyaCommercialLightingKit/TuyaCommercialLightingKit.h>
Open the AppDelegate.m
file and initialize the SDK in [AppDelegate application:didFinishLaunchingWithOptions:]
.
- (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, you are ready for app development.
During the development, you can enable the debug mode and print logs for troubleshooting.
ObjC:
#ifdef DEBUG
[[TuyaSmartSDK sharedInstance] setDebugMode:YES];
#else
#endif
Swift:
#if DEBUG
TuyaSmartSDK.sharedInstance()?.debugMode = true
#else
#endif
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.
You can follow the instructions in Preparation to get the AppKey
, AppSecret
, and security image for iOS
. During the integration with the SDK, make sure the BundleId
, AppKey
, AppSecret
, and security image are consistent with those used on the Tuya IoT Development 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 an API request was made, an error message was returned in the following response:
{
"success" : false,
"errorCode" : "SING_VALIDATE_FALED",
"status" : "error",
"errorMsg" : "Permission Verification Failed",
"t" : 1583208740059
}
Solution: Make sure the BundleId
, AppKey
, AppSecret
, and security image are consistent with those used on the Tuya IoT Development Platform. Any mismatch will cause the authentication to be failed. For more information, see Preparation.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback