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

General Interface

Last Updated on : 2022-02-17 05:33:48download

The general interface is to call the server-side API, and the calling function corresponds to the TuyaSmartRequest class.

Separate call

When a business interface initiates a request separately, the two methods need to be used together.

Interface description

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

Parameter description

Parameters Description
apiName API name
postData Business parameters
getData Public parameters
version API version number
success Success callback
failure Failure callback

Objective-C 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) {

  }];

}

Combination call

When multiple service interfaces initiate requests together, the two methods need to be used together.

Interface description

- (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;

Parameter description

Parameters Description
apiName API name
postData Business parameters
version API version number
getData Public parameters
success Success callback
failure Failure callback

Objective-C 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];
}