Tuya iOS HomeSDK Sample for Swift
Tuya iOS HomeSDK Sample for Swift
This sample demonstrates the use of Tuya iOS HomeSDK to build an IoT app from scratch. Tuya iOS HomeSDK is divided into several function groups to give developers a clear insight into the implementation of different features, including the user registration process, home management for different users, device network configuration, and controls. For device network configuration, the EZ mode and AP mode are implemented. This allows developers to pair devices over Wi-Fi and control the devices over LAN and MQTT. For device control, a common panel is used to send and receive any types of data points.
Prerequisites
- Xcode 12.0 and later
- iOS 12 and later
Use the sample
- The Tuya iOS HomeSDK is distributed through CocoaPods and other dependencies in this sample. Make sure that you have installed CocoaPods. If not, run the following command to install CocoaPods first:
sudo gem install cocoapods
pod setup
- Clone or download this sample, change the directory to the one that includes Podfile, and then run the following command:
pod install
-
This sample requires you to have a pair of keys and a security image from the Tuya IoT Platform, and register a developer account if you don’t have one. Then, perform the following steps:
- Log in to the Tuya IoT platform. In the left-side navigation pane, choose App > SDK Development.
- Click Create to create an app.
- Fill in the required information. Make sure that you enter the valid Bundle ID. It cannot be changed afterward.
- You can find the AppKey, AppSecret, and security image under the Obtain Key tag.
-
Open the
TuyaAppSDKSample-iOS-Swift.xcworkspace
pod generated for you. -
Fill in the AppKey and AppSecret in the AppKey.swift file.
struct AppKey {
static let appKey = "Your AppKey"
static let secretKey = "Your SecretKey"
}
- Download the security image, rename it to
t_s.bmp
, and then drag it to the workspace to be at the same level asInfo.plist
.
Note: The bundle ID, AppKey, AppSecret, and security image must be the same as your app on the Tuya IoT Platform. Otherwise, the sample cannot request the API.
References
For more information about Tuya iOS HomeSDK, see App SDK.