Common APIs

Last Updated on : 2024-04-03 09:33:07download

This topic describes the common APIs provided by the Commercial Lighting App SDK for iOS.

Server APIs

The ThingSmartRequest class includes the common APIs for the server side.

API description

- (void)requestWithApiName:(NSString *)apiName
                  postData:(nullable NSDictionary *)postData
                   getData:(nullable NSDictionary *)getData
                   version:(NSString *)version
                   success:(nullable ThingSuccessID)success
                   failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
apiName The name of the specified API.
postData The service parameters.
getData The common parameters.
version The version number of the specified API.
success The success callback.
failure The failure callback.

Sample code

- (void)getCountryList {
  // self.request = [ThingSmartRequest alloc] init];

  [self.request requestWithApiName:@"tuya.m.country.list" postData:nil version:@"1.0" success:^(id result) {

  } failure:^(NSError *error) {

  }];

}

Combined APIs

API description

Two API methods can be combined in the same API request.

- (void)addMergeRequestWithApiName:(NSString *)apiName
                          postData:(nullable NSDictionary *)postData
                           version:(NSString *)version
                           success:(nullable ThingSuccessID)success
                           failure:(nullable ThingFailureError)failure;

- (void)sendMergeRequestWithGetData:(nullable NSDictionary *)getData
                             success:(nullable ThingSuccessList)success
                            failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
apiName The name of the specified API.
postData The service parameters.
version The version number of the specified API.
getData The common parameters.
success The success callback.
failure The failure callback.

Sample code

- (void)loadHomeDataWithHomeId:(long long)homeId {
  // self.request = [ThingSmartRequest alloc] init];

  [self.request addMergeRequestWithApiName:@"tuya.m.my.group.mesh.list" postData:@{} version:@"1.0" success:nil failure:nil];
  [self.request addApiRequest:@"tuya.m.location.get" postData:@{@"gid": @(homeId)} version:@"2.0" success:nil failure:nil];

  [self.request sendMergeRequestWithGetData:@{@"gid": @(homeId)} success:success failure:failure];
}