iOS App SDK

Tuya Smart iOS SDK Access Guide

Features Overview

Tuya Smart APP SDK provides the interface package for the communication with hardware and Tuya Cloud to accelerate the application development process, including the following features:

  • Hardware functions (network configuration, control, status reporting, regular tasks, groups, firmware upgrades, sharing)
  • Account system (phone number, email registration, login, password reset and other general account functions)
  • Tuya Cloud HTTP API interface package(Calling Tuya Cloud API)

Preparation

Sign up a developer account

Sign up a developer account at Tuya Smart Platform to create a product, create a functional point, and so on. For detailed information, please refer to the access procedure

Obtain an iOS App ID and App Secret

Go to Development Platform - Application Management - Create a new application to obtain an iOS App ID and App Secret to initialize SDK

澳门金沙城中心剧场

Joint mode

  • Device debugging with the hardware control board
  • Simulation debugging through the development platform - analog devices

SDK Demo

SDK Demo is a complete APP incorporating the main flows such as login, registration, sharing, network configuration and control. The Demo code can be used as a reference for the development.

SDK Integration

Using CocoaPods rapid integration (version 8.0 or above is supported)

Add the following content in file Podfile:

platform :ios, '8.0'

target 'Your_Project_Name' do
pod "TuyaSmartKit", :git => "https://github.com/TuyaInc/tuyasmart_ios_sdk.git"
end

7933.com

Execute command pod update in the project’s root directory to begin integration.

For the instructions of CocoaPods, please refer to Recommend to update CocoaPods to the latest version

Initializing SDK

Add the following to the project file PrefixHeader.pch:

#import <TuyaSmartKit/TuyaSmartKit.h>

Open file AppDelegate.m, and use the App ID and App Secret obtained from the development platform in the [AppDelegate application:didFinishLaunchingWithOptions:] method to initialize SDK:

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

Now all the preparatory work has been completed. You can set out to develop your application.

Example code conventions

Following example code, unless otherwise stated, all instances are located in the implementation file of the ViewController class

@interface ViewController : UIViewController

@end

@implementation ViewController

// 一切示例代码均位于此处

@end

For references similar to self.prop, we presume that the prop attribute has been implemented correctly in the ViewController class. For example:

self.device = [[TuyaSmartDevice alloc] initWithDeviceId:@"your_device_id"];

To have it executed properly, we need to add a TuyaSmartDevice attribute in the current ViewController class:

@property (nonatomic, strong) TuyaSmartDevice *device;

And so on.

Conventions for returned error messages

Error messages returned from the SDK interface can be obtained with error.localizedDescription

[[TuyaSmartUser sharedInstance] sendVerifyCode:@"your_country_code" phoneNumber:@"your_phone_number" type:0 success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
// error message
NSLog(@"error message: %@", error.localizedDescription);
}];

Common parameter settings

Public parameters can be passed to SDK, supporting latitude (latitude) and longitude (longitude)

The longitude and latitude need to be submitted to collect the location information of the device:

[[TuyaSmartSDK sharedInstance] setValue:<#latitude#> forKey:@"latitude"];
[[TuyaSmartSDK sharedInstance] setValue:<#longitude#> forKey:@"longitude"];

User Management

Tuya Cloud supports a wide range of user systems: phone, email, UID, etc. Users can log in at their mobile phones with either a verification code or a password. The registration and login processes for each system will be detailed separately later.

In the registration and login method, it is necessary to provide the countryCode parameter to locate the nearest area where Tuya Cloud is available. Data in different available areas are independent. Therefore, an account registered in 中国大陆(86) cannot be used in 美国(1) (user does not exist).

For details about the concept of “available area”, please refer to Tuya Cloud - Available Area

All user-related functions correspond to the TuyaSmartUser class (singleton).

User registration

Note: Following a successful call of the registration method, all functions in the SDK can be used normally (a successful registration is regarded as a successful login). It is not necessary to call the login method anymore.

Phone registration

Phone registration involves the following two steps:

1、Sending a verification code to the phone

- (void)sendVerifyCode {
[[TuyaSmartUser sharedInstance] sendVerifyCode:@"your_country_code" phoneNumber:@"your_phone_number" type:1 success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCode failure: %@", error);
}];
}

2、The verification code received at the mobile phone is then used to register an account

- (void)registerByPhone {
[[TuyaSmartUser sharedInstance] registerByPhone:@"your_country_code" phoneNumber:@"your_phone_number" password:@"your_password" code:@"verify_code" success:^{
NSLog(@"register success");
} failure:^(NSError *error) {
NSLog(@"register failure: %@", error);
}];
}

Email registration

No verification code is required during email registration. Users may register their accounts directly:

- (void)registerByEmail {
[[TuyaSmartUser sharedInstance] registerByEmail:@"your_country_code" email:@"your_email" password:@"your_password" success:^{
NSLog(@"register success");
} failure:^(NSError *error) {
NSLog(@"register failure: %@", error);
}];
}

Email verification registration

Email verification registration involves the following two steps:

1、Sending a verification code to the mail

- (void)sendVerifyCodeByRegisterEmail {

[[TuyaSmartUser sharedInstance] sendVerifyCodeByRegisterEmail:@"your_country_code" email:@"your_email" success:^{
NSLog(@"sendVerifyCodeByRegisterEmail success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCodeByRegisterEmail failure: %@", error);
}];
}

2、The verification code received at the mail is then used to register an account

- (void)registerByEmail {
[[TuyaSmartUser sharedInstance] registerByEmail:@"your_country_code" email:@"your_email" password:@"your_password" code:@"email_code" success:^{
NSLog(@"sendVerifyCodeByRegisterEmail success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCodeByRegisterEmail failure %@",error);
}];
}

UID registration

Tuya Smart provides a UID login system. Customers who have their own user systems may access to our SDK through the UID login system. Those customers need to ensure the uniqueness of their own UIDs.

- (void)registerByUid {
[[TuyaSmartUser sharedInstance] registerByUid:@"your_unique_id" password:@"your_password" countryCode:@"your_country_code" success:^{
NSLog(@"register success");
} failure:^(NSError *error) {
NSLog(@"register failure: %@", error);
}];
}

User login

Upon a successful call, the user’s session will be stored locally by the SDK. When the app is launched next time, the used is logged in by default and no more login process is required.

The session will timeout if the app remains unused for a long time. In this case, the notification of the expired session should be processed to ask the user to log in again. See Handling of session timeout

Mobile phone login

Users can log in at their mobile phones in two ways: with a verification code (no registration required and direct login allowed) or a password (registration required)

Login with a verification code (no registration required, direct login allowed)

Logging in with a mobile phone verification code is similar to the registration process with a mobile phone:

1、Sending a verification code:

- (void)sendVerifyCode {
[[TuyaSmartUser sharedInstance] sendVerifyCode:@"your_country_code" phoneNumber:@"your_phone_number" type:0 success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCode failure: %@", error);
}];
}

2、Login:

- (void)loginByPhoneAndCode {
[[TuyaSmartUser sharedInstance] login:@"your_country_code" phoneNumber:@"your_phone_number" code:@"verify_code" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

Password (registration required)

- (void)loginByPhoneAndPassword {
[[TuyaSmartUser sharedInstance] loginByPhone:@"your_country_code" phoneNumber:@"your_phone_number" password:@"your_password" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

Email login

- (void)loginByEmail {
[[TuyaSmartUser sharedInstance] loginByEmail:@"your_country_code" email:@"your_email" password:@"your_password" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

UID login

- (void)loginByUid {
[[TuyaSmartUser sharedInstance] loginByUid:@"your_unique_id" password:@"your_password" countryCode:@"your_country_code" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

Third-party login

Need to configure corresponding AppID and AppSecret in Tuya Developer Platform - New app - 3rd party login ; Client develops according to the requests of every platform, calling the corresponding login interface of tuyaSDK after obtaining the corresponding code.

Wechat login

- (void)loginByWechat {
/**
* 微疑登录
*
* @param countryCode 国度区号
* @param code 微疑受权登录获得的code
* @param success 操纵胜利回调
* @param failure 操纵失利回调
*/
[[TuyaSmartUser sharedInstance] loginByWechat:@"your_country_code" code:@"wechat_code" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

QQ login

- (void)loginByQQ {
/**
* QQ登录
*
* @param countryCode 国度区号
* @param userId QQ受权登录获得的userId
* @param accessToken QQ受权登录获得的accessToken
* @param success 操纵胜利回调
* @param failure 操纵失利回调
*/
[[TuyaSmartUser sharedInstance] loginByQQ:@"your_country_code" openId:@"qq_open_id" accessToken:@"access_token" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];

}

Facebook login

- (void)loginByFacebook {
/**
* facebook登录
*
* @param countryCode 国度区号
* @param token facebook受权登录获得的token
* @param success 操纵胜利回调
* @param failure 操纵失利回调
*/
[[TuyaSmartUser sharedInstance] loginByFacebook:@"your_country_code" token:@"facebook_token" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];
}

Twitter login


- (void)loginByTwitter {
/**
* twitter登录
*
* @param countryCode 国度区号
* @param key twitter受权登录获得的key
* @param secret twitter受权登录获得的secret
* @param success 操纵胜利回调
* @param failure 操纵失利回调
*/
[[TuyaSmartUser sharedInstance] loginByTwitter:@"your_country_code" key:@"twitter_key" secret:@"twitter_secret" success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login failure: %@", error);
}];

}

Password reset by users

Password reset with a phone number

Resetting a password with the phone number is similar to the registration process:

1、Sending a verification code:

- (void)sendVerifyCode {
[TuyaSmartUser sharedInstance] sendVerifyCode:@"your_country_code" phoneNumber:@"your_phone_number" type:2 success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCode failure: %@", error);
}];
}

2、Resetting the password:

- (void)resetPasswordByPhone {
[TuyaSmartUser sharedInstance] resetPasswordByPhone:@"your_country_code" phoneNumber:@"your_phone_number" newPassword:@"your_password" code:@"verify_code" success:^{
NSLog(@"resetPasswordByPhone success");
} failure:^(NSError *error) {
NSLog(@"resetPasswordByPhone failure: %@", error);
}];
}

Password reset with a mail address

Resetting a password with the E-mail address consists of two steps:

1、Sending a verification code to the mailbox

- (void)sendVerifyCodeByEmail {
[TuyaSmartUser sharedInstance] sendVerifyCodeByEmail:@"your_country_code" email:@"your_email" success:^{
NSLog(@"sendVerifyCodeByEmail success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCodeByEmail failure: %@", error);
}];
}

2、The verification code received is then used to reset the password

- (void)resetPasswordByEmail {
[TuyaSmartUser sharedInstance] resetPasswordByEmail:@"your_country_code" email:@"your_email" newPassword:@"your_password" code:@"verify_code" success:^{
NSLog(@"resetPasswordByEmail success");
} failure:^(NSError *error) {
NSLog(@"resetPasswordByEmail failure: %@", error);
}];
}

Password reset with UID

Resetting a password with the UID does not require a verification code

- (void)resetPasswordByUid {
[TuyaSmartUser sharedInstance] resetPasswordByUid:@"uid" newPassword:@"your_password" countryCode:@"your_country_code" success:^{
NSLog(@"resetPasswordByUid success");
} failure:^(NSError *error) {
NSLog(@"resetPasswordByUid failure: %@", error);
}];
}

4.4 Updating a user’s device list

Using the [TuyaSmartUser syncDeviceWithCloud] method will update the user’s current device list deviceArray and group list groupList.

- (void)reloadDeviceList {
[[TuyaSmartUser sharedInstance] syncDeviceWithCloud:^{
NSLog(@"syncDeviceWithCloud success");
NSLog(@"deviceArray: %@", [TuyaSmartUser sharedInstance].deviceArray);
NSLog(@"groupList: %@", [TuyaSmartUser sharedInstance].groupList);
} failure:^{
NSLog(@"syncDeviceWithCloud failure");
}];
}

Handling device list changes

Listen for the TuyaSmartUserNotificationDeviceArrayChanged notification, so that a notification can be received in the case of any change to the device list [TuyaSmartUser sharedInstance].deviceArray data.

// register notification
- (instancetype)init {
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name: TuyaSmartUserNotificationDeviceArrayChanged object:nil];
}
return self;
}

- (void) reloadData {
// update UI
}

- dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Modify the nickname

- (void)modifyNickname:(NSString *)nickname {
[[TuyaSmartUser sharedInstance] updateNickname:nickname success:^{
NSLog(@"updateNickname success");
} failure:^(NSError *error) {
NSLog(@"updateNickname failure: %@", error);
}];
}

Sign out

- (void)loginOut {
[TuyaSmartUser sharedInstance] loginOut:^{
NSLog(@"logOut success");
} failure:^(NSError *error) {
NSLog(@"logOut failure: %@", error);
}];
}

Disable account

One week after the account is disabled, the account will be permanently disabled and delete all the information in your account. If you login again in one week, your request will be cancelled.

- (void)cancelAccount {
[[TuyaSmartUser sharedInstance] cancelAccount:^{
NSLog(@"cancelAccount success");
} failure:^(NSError *error) {
NSLog(@"cancelAccount failure: %@", error);
}];
}

4.8 Handling of session timeout

When accessing the server interface with an account that has remained unused for a long time, a session timeout error will be returned. Hence, it is required to listen for the TuyaSmartUserNotificationUserSessionInvalid notification to redirect the user to the login page to log in again.


- (void)loadNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionInvalid) name:TuyaSmartUserNotificationUserSessionInvalid object:nil];
}

- (void)sessionInvalid {
if ([[TuyaSmartUser sharedInstance] isLogin]) {
NSLog(@"sessionInvalid");
// loginout
[[TuyaSmartUser sharedInstance] loginOut:nil failure:nil];

// push to MyLoginViewController
MyLoginViewController *vc = [[MyLoginViewController alloc] init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
}

Network Configuration

Tuya’s hardware module supports two modes of network configuration: fast connect mode (TLink, or EZ mode), and hotspot mode (AP mode). The EZ mode is relatively more straight-forward. It is recommended to use the hotspot mode as an alternative only when the network configuration fails with the EZ mode.

Configuration with the EZ mode:

Connect to the router WiFi with the mobile phone -> switch the device to the EZ mode -> network configuration starts at the phone (sending configuration information) -> the device receives the configuration information -> the device connects to the router WiFi -> the device is activated

Distribution process with the AP mode:

Switch the device to the AP mode -> connect the mobile phone to the hot spot on the device -> network configuration starts at the phone (sending configuration information) -> the device receives configuration information -> the device automatically turns off the hot spot -> the device connects to the router WiFi -> the device is activated

All functions related to network configuration correspond to the TuyaSmartActivator class (singleton).

Preparation

SDK has to connect to the Internet to obtain a token from the Tuya Cloud for the network configuration to get started under the EZ/AP mode. The token is valid for 5 minutes, and becomes invalid upon successful configuration (a new token will be required for another network configuration process).

- (void)getToken {
[[TuyaSmartActivator sharedInstance] getToken:^(NSString *token) {
NSLog(@"getToken success: %@", token);
// TODO: startConfigWiFi
} failure:^(NSError *error) {
NSLog(@"getToken failure: %@", error.localizedDescription);
}];
}

Note: If your device firmware’s AP network configuration version is 3.0 or above, the old method [TuyaSmartActivator startConfigWiFi:ssid:password:timeout:] does not work. Please upgrade as soon as possible.

Start network configuration

Network configuration in the EZ mode:

- (void)startConfigWiFi:(NSString *)ssid password:(NSString *)password token:(NSString *)token {
-7933.com
[TuyaSmartActivator sharedInstance].delegate = self;

// start config
[[TuyaSmartActivator sharedInstance] startConfigWiFi:TYActivatorModeEZ ssid:ssid password:password token:token timeout:100];
}

#pragma mark - TuyaSmartActivatorDelegate
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error {

if (!error && deviceModel) {
// success
}

if (error) {
// failure
}
}

Network configuration in the AP mode works in the same way as the EZ mode, provided that the first parameter of [TuyaSmartActivator startConfigWiFi:ssid:password:token:timeout:] is changed to TYActivatorModeAP. Note that ssid and password refer to the router’s hotspot name and password, rather than the name and password of the device.

S network configuration

After the network configuration operation is started, the app will broadcast the network configuration information continuously (until network configuration succeeds or times out). To cancel the operation, or when network configuration is completed, the [TuyaSmartActivator sConfigWiFi] method should be called.

- (void)sConfigWifi {
[TuyaSmartActivator sharedInstance].delegate = nil;
[[TuyaSmartActivator sharedInstance] sConfigWiFi];
}

Device Control

All device control functions correspond to the TuyaSmartDevice class, which need to be initialized with a device ID. A wrong device ID may lead to initialization failure, returning a nil.

A device ID refers to the devId field under TuyaSmartDeviceModel, which can be obtained from the user device list.

Update device information

Update the information for an individual device

- (void)updateDeviceInfo {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

__weak typeof(self) weakSelf = self;
[self.device syncWithCloud:^{
NSLog(@"syncWithCloud success");
NSLog(@"deviceModel: %@", weakSelf.device.deviceModel);
} failure:^{
NSLog(@"syncWithCloud failure");
}];
}

Update the information for all devices

SeeUser Management - Update Device List

Device function points

The dps attribute of the TuyaSmartDeviceModel class (NSDictionary type) defines the current status of the device, which is called a data point (DP) or function point.

Each key in the dps dictionary corresponds to a dpId of a function point, while the value corresponds the dpValue of the function point. dpValue is the value for that function point.

For the definition of product function points, see the product functions at Tuya Developer Platform, as shown below:

金沙网站,js3311com

Control commands are sent in the following format:

{"<dpId>":"<dpValue>"}

According to the function points of the product defined on the background, the example code is as follows:

- (void)publishDps {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

NSDictionary *dps;
//设置dpId为1的布尔型功用点示例 感化:开关翻开
dps = @{@"1": @(YES)};

//设置dpId为4的字符串型功用点示例 感化:设置RGB色彩为ff5500
dps = @{@"4": @"ff5500"};

//设置dpId为5的罗列型功用点示例 感化:设置档位为2档
dps = @{@"5": @"2"};

//设置dpId为6的数值型功用点示例 感化:设置温度为20°
dps = @{@"6": @(20)};

//设置dpId为15的透传型(byte数组)功用点示例 感化:透传红外数据为1122
dps = @{@"15": @"1122"};

//多个功用兼并发送
dps = @{@"1": @(YES), @"4": @(ff5500)};

[self.device publishDps:dps success:^{
NSLog(@"publishDps success");

//下发胜利,状况上报经由过程 deviceDpsUpdate要领 回调

} failure:^(NSError *error) {
NSLog(@"publishDps failure: %@", error);
}];


}
Note:
  • Make sure the data types are correct when sending a control command.
    For example, when the data type of a function point is numeric (value), the control command is supposed to be @{@"2": @(25)} instead of @{@"2": @"25"}
  • A byte array sent through transparent transmission type is a string format, for which all letters must be lowercase with an even number of bits.
    For example, a correct format should be: @{@"1": @"011f"} instead of @{@"1": @"11f"}

For further explanations about function points, please see Quick Start - Concepts about Function Points

Device status update

After the TuyaSmartDeviceDelegate proxy protocol is achieved, a callback of device status changes can be used to refresh the UI of the application’s device control panel.

- (void)initDevice {
self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];
self.device.delegate = self;
}

#pragma mark - TuyaSmartDeviceDelegate

- (void)device:(TuyaSmartDevice *)device dpsUpdate:(NSDictionary *)dps {
NSLog(@"deviceDpsUpdate: %@", dps);
// TODO: update UI
}

- (void)deviceInfoUpdate:(TuyaSmartDevice *)device {
//device name,online update
}

- (void)deviceRemoved:(TuyaSmartDevice *)device {
// device remove
}

Modify the device name

- (void)modifyDeviceName:(NSString *)mame {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

[self.device updateName:name success:^{
NSLog(@"updateName success");
} failure:^(NSError *error) {
NSLog(@"updateName failure: %@", error);
}];
}

Remove a device

Once a device is removed, it will once again enter a network-pending state (fast connect mode).

- (void)removeDevice {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

[self.device remove:^{
NSLog(@"remove success");
} failure:^(NSError *error) {
NSLog(@"remove failure: %@", error);
}];
}

Firmware upgrade

Firmware upgrade process:

Obtain the device upgrade information -> Send the upgrade command for the networking module -> Upgrade of the networking module succeeds -> Send the upgrade command for the device control module -> Upgrade of the device control module succeeds

Obtain the device upgrade information:

- (void)getFirmwareUpgradeInfo {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

[self.device getFirmwareUpgradeInfo:^(TuyaSmartFirmwareUpgradeModel *devModel, TuyaSmartFirmwareUpgradeModel *gwModel) {
NSLog(@"getFirmwareUpgradeInfo success");
} failure:^(NSError *error) {
NSLog(@"getFirmwareUpgradeInfo failure: %@", error);
}];
}

Send upgrade commands:

- (void)upgradeFirmware {
// self.device = [TuyaSmartDevice deviceWithDeviceId:@"your_device_id"];

NSInteger type = 1;
[self.device upgradeFirmware:type success:^{
NSLog(@"upgradeFirmware success");
} failure:^(NSError *error) {
NSLog(@"upgradeFirmware failure: %@", error);
}];
}

Note: type 1: upgrade networking module; 2: upgrade device control module

Callback interface:

- (void)deviceFirmwareUpgradeSuccess:(TuyaSmartDevice *)device {
//success
}

- (void)deviceFirmwareUpgradeFailure:(TuyaSmartDevice *)device {
// failure
}

- (void)device:(TuyaSmartDevice *)device firmwareUpgradeProgress:(NSInteger)type progress:(double)progress {
// Upgrade Progress
// type 1: upgrade networking module; 2: upgrade device control module
}

Device Sharing

We provides two sharing methods: One is sharing with users, mainly used to share devices with families. Once User A shares devices with his/her families, families may control all devices of User A. The other method is sharing with other devices. Sometimes you need to share some devices with families, you can just share corresponding devices with friends and your friends can not control other devices. Besides, you can set that all the devices which are shared cannot be renamed, removed, upgraded firmware, performed factory reset and so on (while sending device control commands and getting status updates are allowed).

User shares(sharing based on user dimensions)

All the functions related to user sharing correspond to TuyaSmartMember class.

Adding shares

Mobile phone and email sharing

- (void)addShare {
// self.member = [[TuyaSmartMember alloc] init];

[self.member addNewMember:@"member_name" phoneCode:@"member_country_code" userAccount:@"member_phone_or_email" relationship:TYRelationshipFriend success:^{
NSLog(@"addNewMember success");
} failure:^(NSError *error) {
NSLog(@"addNewMember failure: %@", error);
}];
}

UID sharing

- (void)addShare {
// self.member = [[TuyaSmartMember alloc] init];

[self.member addNewMember:@"member_name" uid:@"member_unique_id" relationship:TYRelationshipFriend success:^{
NSLog(@"addNewMember success");
} failure:^(NSError *error) {
NSLog(@"addNewMember failure: %@", error);
}];
}

Get the list of shares

Get the list of shares (i.e. users who can control your devices):

- (void)initMemberList {
// self.member = [[TuyaSmartMember alloc] init];

[self.member getMemberList:^(NSArray<TuyaSmartMemberModel *> *list) {
NSLog(@"getMemberList success: %@", list);
} failure:^{
NSLog(@"getMemberList failure");
}];
}

Get the list of sharing users (i.e. users whose devices you can control):

- (void)initReceiveMemberList {
// self.member = [[TuyaSmartMember alloc] init];

[self.member getReceiveMemberList:^(NSArray<TuyaSmartMemberModel *> *list) {
NSLog(@"getReceiveMemberList success: %@", list);
} failure:^{
NSLog(@"getReceiveMemberList failure");
}];
}

Modify remarks

Modify the name of a shared member:

- (void)modifyMemberName:(TuyaSmartMemberModel *)memberModel name:(NSString *)name {
// self.member = [[TuyaSmartMember alloc] init];

[self.member modifyMemberName:memberModel.memberId name:name success:^{
NSLog(@"modifyMemberName success");
} failure:^(NSError *error) {
NSLog(@"modifyMemberName failure: %@", error);
}];
}

Modify the name of a sharing member:

- (void)modifyReceiveMemberName:(TuyaSmartMemberModel *)memberModel name:(NSString *)name {
// self.member = [[TuyaSmartMember alloc] init];

[self.member modifyReceiveMemberName:memberModel.memberId name:name success:^{
NSLog(@"modifyReceiveMemberName success");
} failure:^(NSError *error) {
NSLog(@"modifyReceiveMemberName failure: %@", error);
}];

Delete shares

After deleting a share, you will not be able to use his or her devices, or he/she will not be able to use your devices.

- (void)removeMember:(TuyaSmartMemberModel *)memberModel {
// self.member = [[TuyaSmartMember alloc] init];

[self.member removeMember:memberModel.memberId success:^{
NSLog(@"removeMember success");
} failure:^(NSError *error) {
NSLog(@"removeMember failure: %@", error);
}];
}

Device shares (sharing based on device dimension )

All the functions related to device shares correspond to TuyaSmartDeviceShare class.

Add shares


- (void)addMemberShare {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService addMemberShare:@"country_code" userAccount:@"user_account" devIds:@"devId list" autoSharing:YES success:^(TuyaSmartShareMemberModel *model) {

NSLog(@"addShare success");

} failure:^(NSError *error) {

NSLog(@"addShare failure: %@", error);

}];

}

Get the list of shared users

get the lists of all users who share on their own initiative


- (void)getShareMemberList {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService getShareMemberList:^(NSArray<TuyaSmartShareMemberModel *> *list) {

NSLog(@"getShareMemberList success");

} failure:^(NSError *error) {

NSLog(@"getShareMemberList failure: %@", error);

}];

}

get the list of users who get the shares


- (void)getReceiveMemberList {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService getReceiveMemberList:^(NSArray<TuyaSmartShareMemberModel *> *list) {

NSLog(@"getReceiveMemberList success");

} failure:^(NSError *error) {

NSLog(@"getReceiveMemberList failure: %@", error);

}];

}

Get the shared data of users

get single shared data of user who shares on his/her own initiative


- (void)getShareMemberDetail {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService getShareMemberDetail:@"member_id" success:^(TuyaSmartShareMemberDetailModel *model) {

NSLog(@"getShareMemberDetail success");

} failure:^(NSError *error) {

NSLog(@"getShareMemberDetail failure: %@", error);

}];

}

get single shared data of user who receive shares


- (void)getReceiveMemberDetail {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService getReceiveMemberDetail:@"member_id" success:^(TuyaSmartShareMemberDetailModel *model) {

NSLog(@"getReceiveMemberDetail success");

} failure:^(NSError *error) {

NSLog(@"getReceiveMemberDetail failure: %@", error);

}];

}

Delete shares

delete sharers who share on their own initiative


- (void)removeShareMember {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService removeShareMember:@"member_id" success:^{

NSLog(@"removeShareMember success");

} failure:^(NSError *error) {

NSLog(@"removeShareMember failure: %@", error);

}];

}

delete users who receive shares


- (void)removeReceiveMember {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService removeReceiveMember:@"member_id" success:^{

NSLog(@"removeReceiveMember success");

} failure:^(NSError *error) {

NSLog(@"removeReceiveMember failure: %@", error);

}];

}

Modify nickname

modify the nicknames of sharers who share on their own initiative


- (void)updateShareMemberName {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService updateShareMemberName:@"member_id" name:@"name" success:^{

NSLog(@"updateShareMemberName success");

} failure:^(NSError *error) {

NSLog(@"updateShareMemberName failure: %@", error);

}];

modify nickname of person who receive shares


- (void)updateReceiveMemberName {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService updateReceiveMemberName:@"member_id" name:@"name" success:^{

NSLog(@"updateReceiveMemberName success");

} failure:^(NSError *error) {

NSLog(@"updateReceiveMemberName failure: %@", error);

}];

}

Operations of sharing a single device

Add shares of a single device


- (void)addDeviceShare {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService addDeviceShare:@"member_id" devId:@"dev_id" success:^{

NSLog(@"addDeviceShare success");

} failure:^(NSError *error) {

NSLog(@"addDeviceShare failure: %@", error);

}];

}

Delete shares of a single device


- (void)removeDeviceShare {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService removeDeviceShare:@"member_id" devId:@"dev_id" success:^{

NSLog(@"removeDeviceShare success");

} failure:^(NSError *error) {

NSLog(@"removeDeviceShare failure: %@", error);

}];

}

Delete shares of a single device


- (void)removeDeviceShare {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService removeDeviceShare:@"dev_id" success:^{

NSLog(@"removeDeviceShare success");

} failure:^(NSError *error) {

NSLog(@"removeDeviceShare failure: %@", error);

}];

}

Sharing automatically

Set whether the newly add device is automatically shared


- (void)enableNewDeviceAutoShare {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService enableNewDeviceAutoShare:YES memberId:@"member_id" success:^{

NSLog(@"enableNewDeviceAutoShare success");

} failure:^(NSError *error) {

NSLog(@"enableNewDeviceAutoShare failure: %@", error);

}];

}

Get the list of user who share the devices


- (void)getDeviceShareMemberList {
//self.shareService = [TuyaSmartDeviceShare new];

[self.shareService getDeviceShareMemberList:@"dev_id" success:^(NSArray<TuyaSmartShareMemberModel *> *list) {

NSLog(@"getDeviceShareMemberList success");

} failure:^(NSError *error) {
-澳门金沙城中心剧场
NSLog(@"getDeviceShareMemberList failure: %@", error);

}];
}

Get the devices that can be shared by current users


- (void)getShareDeviceList {
//self.shareService = [TuyaSmartDeviceShare new];

NSArray *list = self.shareService.getShareDeviceList;

}

Regular Tasks

The design ideas are shown below:

Timer

All functions related to regular tasks correspond to the TuyaSmartTimer class.

Note: loops: @“0000000”, each bit, 0: off, 1: on, representing from left to right: Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Add a regular task

Add a timer under a specified task of a specified device

- (void)addTimer {
// self.timer = [[TuyaSmartTimer alloc] init];
NSDictionary *dps = @{@"1": @(YES)};

[self.timer addTimerWithTask:@"timer_task_name" loops:@"1000000" devId:@"device_id" time:@"18:00" dps:dps success:^{
NSLog(@"addTimerWithTask success");
} failure:^(NSError *error) {
NSLog(@"addTimerWithTask failure: %@", error);
}];
}

Obtain timed task status

Obtain all task models under a specified device

- (void)getTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer getTimerTaskStatusWithDeviceId:@"device_id" success:^(NSArray<TPTimerTaskModel *> *list) {
NSLog(@"getTimer success %@:", list);
} failure:^(NSError *error) {
NSLog(@"getTimer failure: %@", error);
}];
}

Update timed task status

Update the status of a specified task under a specified device, 0: off, 1: on

- (void)updateTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer updateTimerTaskStatusWithTask:@"timer_task_name" devId:@"device_id" status:1 success:^{
NSLog(@"updateTimer success");
} failure:^(NSError *error) {
NSLog(@"updateTimer failure: %@", error);
}];
}

Update timer status

Update the status of a specified timer under a specified task under a specified device, 0: off, 1: on

- (void)updateTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer updateTimerStatusWithTask:@"timer_task_name" devId:@"device_id" timerId:@"timer_id" status:1 success:^{
NSLog(@"updateTimer success");
} failure:^(NSError *error) {
NSLog(@"updateTimer failure: %@", error);
}];
}

Delete a timer

Delete a specified timer under a specified task under a specified device

- (void)removeTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer removeTimerWithTask:@"timer_task_name" devId:@"device_id" timerId:@"timer_id" success:^{
NSLog(@"removeTimer success");
} failure:^(NSError *error) {
NSLog(@"removeTimer failure: %@", error);
}];
}

Update a timer

Update a specified timer under a specified task under a specified device

- (void)updateTimer {
// self.timer = [[TuyaSmartTimer alloc] init];
NSDictionary *dps = @{@"1": @(YES)};

[self.timer updateTimerWithTask:@"timer_task_name" loops:@"1000000" devId:@"device_id" timerId:@"timer_id" time:@"18:00" dps:dps success:^{
NSLog(@"updateTimer success");
} failure:^(NSError *error) {
NSLog(@"updateTimer failure: %@", error);
}];
}

Obtain all timers under a timed task

Obtain all timer models under a specified task under a specified device

- (void)getTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer getTimerWithTask:@"timer_task_name" devId:@"device_id" success:^(NSArray<TPTimerModel *> *list) {
NSLog(@"getTimer success %@:", list);
} failure:^(NSError *error) {
NSLog(@"getTimer failure: %@", error);
}];
}

Obtain all timers under all timed tasks of a device

Obtain all timer models under all specified stask of a specified device

- (void)getTimer {
// self.timer = [[TuyaSmartTimer alloc] init];

[self.timer getAllTimerWithDeviceId:@"device_id" success:^(NSDictionary *dict) {
NSLog(@"getTimer success %@:", list);
} failure:^(NSError *error) {
NSLog(@"getTimer failure: %@", error);
}];
}

Group Management

The Tuya Cloud supports a group management system: users can create a group, edit the group name, manage devices in the group, control multiple devices via the group, and dismiss the group.

All group-related functions correspond to the TuyaSmartGroup class, which need to be initialized with a group ID. A wrong group ID may lead to initialization failure, returning a nil.

A group ID refers to the groupId field under TuyaSmartGroupModel, which can be obtained from the user device list.

Create a group

- (void)createNewGroup {
//self.smartGroup = [[TuyaSmartGroup alloc] init];
[self.smartGroup createGroupWithName:@"your_group_name" productId:@"your_group_product_id" devIdList:(NSArray<NSString *> *)selectedDevIdList success:^(TuyaSmartGroup *group) {
NSLog(@"create new group success %@:", group);
} failure:^(NSError *error) {
NSLog(@"create new group failure");
}];
}

Obtain the list of devices in a group

A list of devices for a product will be obtained when no group has been created

- (void)getGroupDevList {
[TuyaSmartGroup getDevList:@"your_productId" success:^(NSArray<TuyaSmartGroupDevListModel *> *list) {
NSLog(@"getDevList success");
} failure:^(NSError *error) {
NSLog(@"getDevList failure %@",error);
}];
}

A list of devices in a group will be obtained once the group has been created

- (void)getGroupDevList {
// self.smartGroup = [TuyaSmartGroup groupWithGroupId:@"your_group_id"];
[self.smartGroup getDevList:@"your_productId" success:^(NSArray<TuyaSmartGroupDevListModel *> *list) {
NSLog(@"getDevList success");
} failure:^(NSError *error) {
NSLog(@"getDevList failure %@",error);
}];
}

Issue group dp commands

- (void)publishDps {
// self.smartGroup = [TuyaSmartGroup groupWithGroupId:@"your_group_id"];

NSDictionary *dps = @{@"1": @(YES)};
[self.smartGroup publishDps:dps success:^{
NSLog(@"publishDps success");
} failure:^(NSError *error) {
NSLog(@"publishDps failure: %@", error);
}];

Modify the group name

- (void)updateGroupName {
// self.smartGroup = [TuyaSmartGroup groupWithGroupId:@"your_group_id"];

[self.smartGroup updateGroupName:@"your_group_name" success:^{
NSLog(@"update group name success");
} failure:^(NSError *error) {
NSLog(@"update group name failure: %@", error);
}];
}

Modify the list of devices in the group

- (void)updateGroupRelations {
// self.smartGroup = [TuyaSmartGroup groupWithGroupId:@"your_group_id"];

[self.smartGroup updateGroupRelations:(NSArray<NSString *> *)selectedDevIdList success:^ {
NSLog(@"update group relations success");
} failure:^(NSError *error) {
NSLog(@"update group relations failure: %@", error);
}];
}

Dismiss a group

- (void)dismissGroup {
// self.smartGroup = [TuyaSmartGroup groupWithGroupId:@"your_group_id"];

[self.smartGroup dismissGroup:^{
NSLog(@"dismiss group success");
} failure:^(NSError *error) {
NSLog(@"dismiss group failure: %@", error);
}];
}

Callback interface

Data callback update after group DP is issued


#pragma mark - TuyaSmartGroupDelegate

- (void)group:(TuyaSmartGroup *)group dpsUpdate:(NSDictionary *)dps {
// update group UI
}

Smart scene

Tuya cloud supports users to set weather or device conditions according to the actual living scenes. When the conditions are satisfied, one or several devices will execute corresponding tasks.

Scene related functions corresponding to two classes including TuyaSmartScene and TuyaSmartSceneManager, TuyaSmartScene provides four operations including add, modify, delete and execute for single scene which need to initialize using scene id. Scene id is the sceneId field of TuyaSmartSceneModel, it can be gotten from scene lists.TuyaSmartSceneManager class(singleton) mainly provides all the related data of conditions, tasks, devices, cities in the scene. Before using the related interface of smart scene, you need to know the concepts of scene condition and scene task first.

Scene condition

Scene condition corresponds to TuyaSmartSceneConditionModel class, Tuya cloud supports two condition types:

  • Weather condition:including weather, humidity, temperature, PM2.5, air condition, sunset and sunrise, user can choose current city when choosing weather condition
  • Device condition:user can choose the functional status of a device in advance, it will intrigue the tasks of the current scene when the device in this status, however one device cannot be the both condition and task at the same time to avoid the confliction of the operation.

Scene task

Scene task means one or more devices execute a certain operation when this scene satisfied the given weather or device condition, it corresponds to TuyaSmartSceneActionModel class.

Get the list of the scene

- (void)getSmartSceneList {
[[TuyaSmartSceneManager sharedInstance] getSceneList:^(NSArray<TuyaSmartSceneModel *> *list) {
NSLog(@"get scene list success %@:", list);
} failure:^(NSError *error) {
NSLog(@"get scene list failure: %@", error);
}];
}

Add scene

Add scene needs to import scene name, condition (currently only support one condition), a task list (at least one task), also can only set the name and tasks, not set conditions, but need to manually execute. Using [TuyaSmartSceneConditionModel initWithSceneDPModel:] method to construct conditions and using [TuyaSmartSceneActionModel initWithSceneDPModel:] method to construct tasks.

- (void)addSmartScene {
[TuyaSmartScene addNewScene:@"your_scene_name" condition:(TuyaSmartSceneConditionModel *)condition actionList:(NSArray<TuyaSmartSceneActionModel*> *)actionList success:^(TuyaSmartSceneModel *sceneModel) {
NSLog(@"add scene success %@:", sceneModel);
} failure:^(NSError *error) {
NSLog(@"add scene failure: %@", error);
}];
}

Modify scene

modify the name, condition or task of the scene

- (void)modifySmartScene {
// self.smartScene = [TuyaSmartScene sceneWithSceneId:@"your_scene_id"];
[self.smartScene modifyScene:@"your_scene_name" condition:condition actionList:self.dataSource success:^{
NSLog(@"modify scene success");
} failure:^(NSError *error) {
NSLog(@"modify scene failure: %@", error);
}];
}

Delete scene

- (void)deleteSmartScene {
// self.smartScene = [TuyaSmartScene sceneWithSceneId:@"your_scene_id"];
[self.smartScene deleteScene:^{
NSLog(@"delete scene success");
} failure:^(NSError *error) {
NSLog(@"delete scene failure: %@", error);
}];
}

Execute scene

- (void)executeSmartScene {
// self.smartScene = [TuyaSmartScene sceneWithSceneId:@"your_scene_id"];
[self.smartScene exeuteScene:^{
NSLog(@"execute scene success");
} failure:^(NSError *error) {
NSLog(@"execute scene failure: %@", error);
}];
}

Get the list of conditions

Get the list of conditions, such as temperature, humidity, weather, PM2.5, sunset and sunrise and so on. Note: Device can also be the condition.

- (void)getConditionList {
[[TuyaSmartSceneManager sharedInstance] getConditionList:^(NSArray<TuyaSmartSceneDPModel *> *list) {
NSLog(@"get condition list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get condition list failure: %@", error);
}];
}

Get the device list of the action

When adding actions, you need to get the device list of the action to choose which corresponding action to be executed.

- (void)getActionDeviceList {
[[TuyaSmartSceneManager sharedInstance] getActionDeviceList:^(NSArray<TuyaSmartDeviceModel *> *list) {
NSLog(@"get action device list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get action device list failure: %@", error);
}];
}

Get the conditional device list

When adding conditions, not only the weather condition such as temperature, humidity can be the execution conditions, but also device can be the condition, which means getting the conditional device list, then choosing an action related to device execution as a condition.

- (void)getConditionDeviceList {
[[TuyaSmartSceneManager sharedInstance] getConditionDeviceList:^(NSArray<TuyaSmartDeviceModel *> *list) {
NSLog(@"get condition device list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get condition device list failure: %@", error);
}];
}

Get the dp list of action device

When adding or modifying scene action, you need to get device dp list according to the device that has been chosen after choosing scene, then choose a dp functional point, namely appointing this device to execute this action.

- (void)getActionDeviceDPList {
[[TuyaSmartSceneManager sharedInstance] getActionDeviceDPList:@"your_device_id" success:^(NSArray<TuyaSmartSceneDPModel *> *list) {
NSLog(@"get action device dp list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get action device dp list failure: %@", error);
}];
}

Get dp list of conditional device

When choosing the scene conditions, choose the device, and you need to get device dp list according to the deviceId of the device that has been chosen, then choose a dp function point, namely appointing that the device performs the dp function as an execution condition for the scene.

- (void)getCondicationDeviceDPList {
[[TuyaSmartSceneManager sharedInstance] getCondicationDeviceDPList:@"your_device_id" success:^(NSArray<TuyaSmartSceneDPModel *> *list) {
NSLog(@"get condition device dp list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get condition device dp list failure: %@", error);
}];
}

Get the list of city

When choosing the weather condition, users can choose current city according to the city list gotten by country codes. (Note:The list of cities in some foreign countries may not be complete for the time being. If it is a foreign user, it is recommended to get the city information according to longitude and latitude)

- (void)getCityList {
[[TuyaSmartSceneManager sharedInstance] getCityList:@"your_country_code" success:^(NSArray<TuyaSmartCityModel *> *list) {
NSLog(@"get city list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get city list failure: %@", error);
}];
}

Get the city information according to longitude and latitude

- (void)getCityInfo {
[[TuyaSmartSceneManager sharedInstance] getCityInfo:@"your_location_latitude" longitude:@"your_location_longitude" success:^(TuyaSmartCityModel *city) {
NSLog(@"get city info success:%@", city);
} failure:^(NSError *error) {
NSLog(@"get city info failure:%@", error);
}];
}

Get the city information according to city id

get the city information according to city id, the city id can be gotten from city list

- (void) getCityInfo {
[[TuyaSmartSceneManager sharedInstance] getCityInfoByCityId:@"your_city_id" success:^(TuyaSmartCityModel *city) {
NSLog(@"get city info success:%@", city);
} failure:^(NSError *error) {
NSLog(@"get city info failure:%@", error);
}];
}

Message center

All the functions in message center correspond to TuyaSmartMessage class, which supports get the list of message, batch delete message and whether the messages are updated.

Get the list of message

- (void)getMessageList {
// self.smartMessage = [[TuyaSmartMessage alloc] init];
[self.smartMessage getMessageList:^(NSArray<TuyaSmartMessageListModel *> *list) {
NSLog(@"get message list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get message list failure:%@", error);
}];
}

Delete message

Batch delete messages,messgeIdList is the id array of the message that needs to be deleted, message id can be gotten from message list.

- (void)deleteMessage {
// self.smartMessage = [[TuyaSmartMessage alloc] init];
[self.smartMessage deleteMessage:(NSArray <NSString *> *)messgeIdList success:^{
NSLog(@"delete message success");
} failure:^(NSError *error) {
NSLog(@"delete message failure:%@", error);
}];
}

Get the timestamp for the latest message

Get the timestamp for the latest message, can be used to compare with the timestamp for the latest message, if it is greater than the local update time, the red dots are displayed, indicating there are new messages.

- (void)getMessageMaxTime {
// self.smartMessage = [[TuyaSmartMessage alloc] init];
[self.smartMessage getMessageMaxTime:^(int result) {
NSLog(@"get message max time success:%d", result);
} failure:^(NSError *error) {
NSLog(@"get message max time failure:%@", error);
}];
}

Feedback

When users have some problems, they can add feedbacks. When adding feedbacks, users can choose the type of the feedback, then write down the problem and submit it. After submitting, it will generate the correspond feedback session according to the type they chose before, users can keep on writing the feedback and submitting it in this session at the same time, it will be displayed in the feedback list of this session.

All the functions of feedback correspond to TuyaSmartFeedback class, which supports to get the list of feedback session, list of feedback content, list of feedback in the session and add feedback.

Get the list of feedback session

get a list of user submitted feedback sessions

- (void)getFeedbackTalkList {
// self.feedBack = [[TuyaSmartFeedback alloc] init];
[self.feedBack getFeedbackTalkList:^(NSArray<TuyaSmartFeedbackTalkListModel *> *list) {
NSLog(@"get feedback talk list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get feedback talk list failure:%@", error);
}];
}

Get the list of the feedback type

Get a list of corresponding feedback items in the feedback session, hdId and hdType field can be gotten from TuyaSmartFeedbackTalkListModel.

- (void)getFeedbackList {
// self.feedBack = [[TuyaSmartFeedback alloc] init];
[self.feedBack getFeedbackList:@"your_hdId" hdType:(NSInteger)hdType success:^(NSArray<TuyaSmartFeedbackModel *> *list) {
NSLog(@"get feedback list success:%@", list);
} failure:^(NSError *error) {
NSLog(@"get feedback list failure:%@", error);
}];
}

Get the list of the feedback type

When adding feedbacks, you can choose the type of feedback in advance.

- (void)getFeedbackTypeList {
// self.feedBack = [[TuyaSmartFeedback alloc] init];
[self.feedBack getFeedbackTypeList:^(NSArray<TuyaSmartFeedbackTypeListModel *> *list) {
NSLog(@"get feedback type list success:%@", list);
} failure:^(NSError *error) {
NSLog-金沙网站,js3311com(@"get feedback type list failure:%@", error);
}];
}

Add feedback

Submit the content of the feedback which input by users.hdId and hdType fields can be gotten from TuyaSmartFeedbackTalkListModel.

- (void)addFeedback {
// self.feedBack = [[TuyaSmartFeedback alloc] init];
[self.feedBack addFeedback:@"your_feedback_content" hdId:@"your_hdId" hdType:(NSInteger)hdType success:^{
NSLog(@"add feedback success");
} failure:^(NSError *error) {
NSLog(@"add feedback failure:%@", error);
}];
}

Common interface

call api interface of server


- (void)load {
//self.request = [TuyaSmartRequest alloc] init];

/**
* 恳求服务端接口
*
* @param apiName 接口称号
* @param postData 业务入参
* @param version 接口版本号
* @param success 操纵胜利回调
* @param failure 操纵失利回调
*/
[self.request requestWithApiName:@"api_name" postData:@"post_data" version:@"api_version" success:^(id result) {

} failure:^(NSError *error) {

}];

}

Integrate Push

Tuya platform supports push function of the app developed based on Tuya SDK, it supports sending operation push and warning push of the product.

Configure Xcode

click the project - TARGETS - Capabilities, turn on the on-off Push Notification on-off, the effect is shown as below:

ios-push

Configure Tuya developer platform

login Tuya developer platform - enter the correspond APP - configure push推送设置 - upload push certification

ios-push-setting

Initialization

Initialize push in the method of didFinishLaunchingWithOptions

    
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


[application registerForRemoteNotifications];
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];


if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
//iOS10
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
UNAuthorizationOptions types10 = UNAuthorizationOptionBadge|UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
[center requestAuthorizationWithOptions:types10 completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
} else {
}
}];
}

}

Register pushId

Register pushId in didRegisterForRemoteNotificationsWithDeviceToken to Tuya SDK.


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {


NSString *pushId = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@" " withString:@""]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""];

NSLog(@"pushId is %@",pushId);

[[TuyaSmartSDK sharedInstance] setValue:pushId forKey:@"deviceToken"];
}

Receive notification

Receiving the remote notification, execute in the agency method of didReceiveRemoteNotification

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {


}

Send Push

New operation push

Tuya Developer platform - Operation - Message - New notification

New warning push

Tuya Developer platform - Product - Advanced features - Alarm management - New trigger

FAQ

1、 Why there an error when execute pod install?
Confirm that the version of cocoapod is latest,execute pod --version command to check the version of pod, and confirm that the version is over 1.3.0.

2、Why there is an error of Error Domain=NSURLErrorDomain Code=-999 "已勾销" after calling SDK interface? Confirm that the requested object is global variable, otherwise it will be released ahead of time. For instance: self.feedBack = [[TuyaSmartFeedback alloc] init];

3、How to open debug mode and print logs? After initializing SDK, call the following code: [[TuyaSmartSDK sharedInstance] setDebugMode:YES];

4、The device doesn’t report status when the control instruction is issued. Verify that the data type of the function point is correct, for example, if the data type of the function point is numeric(value), the control command it should send is @{@“2”: @(25)} rather than @{@“2”: @“25”}.

5、In iOS 12, [[TuyaSmartActivator sharedInstance] currentWifiSSID] can’t get ssid. Xcode 10 should open access wifi information capability to get ssid. This can be found at: Xcode -> [Project Name] -> Targets -> [Target Name] -> Capabilities -> Access WiFi Information -> ON

400-881-8611