English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Common API Methods

Last Updated on : 2022-03-03 06:52:44download

Server API methods

Server APIs are supported by the TuyaSmartRequest class.

API description

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

Parameters

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

Example

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

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

  } failure:^(NSError *error) {

  }];

}

Combined APIs

API description

Calls multiple APIs in the same request. The following methods are required:

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

- (void)sendMergeRequestWithGetData:(nullable NSDictionary *)getData
                            success:(nullable TYSuccessList)success
                            failure:(nullable TYFailureError)failure;

Parameters

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

Example

- (void)loadHomeDataWithHomeId:(long long)homeId {
  // self.request = [TuyaSmartRequest 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];
}