设备分组
更新时间:2024-12-11 19:02:54
对用户下的设备进行分组管理
@protocol RTCXDeviceGroupProtocol <NSObject>
/**
* 创建设备分组
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupCreatWithReq:(nonnull RTCXGroupCreatReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 删除设备分组
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupDeleteWithReq:(nonnull RTCXGroupDeleteReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 更新设备分组信息
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupUpdateWithReq:(nonnull RTCXGroupUpdateReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 设备分组列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupListWithReq:(nonnull RTCXGroupListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 添加设备到分组
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupAddDeviceWithReq:(nonnull RTCXGroupAddDeviceReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 分组中删除设备
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)groupDeleteDeviceWithReq:(nonnull RTCXGroupDeleteDeviceReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
@end
使用 RTCXDeviceSDK 单例宏对象调用示例如下:
创建设备分组
RTCXGroupCreatReq *req = [[RTCXGroupCreatReq alloc] init];
req.name = self.groupName;
req.iotIdList = iotIds;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupCreatWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf.navigationController popViewControllerAnimated:YES];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
删除设备分组
RTCXGroupDeleteReq *req = [[RTCXGroupDeleteReq alloc] init];
req.groupId = model.groupId;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupDeleteWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf getGroupList];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
更新设备分组信息
RTCXGroupUpdateReq *req = [[RTCXGroupUpdateReq alloc] init];
req.groupId = model.groupId;
req.name = name;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupUpdateWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf getGroupList];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
设备分组列表
RTCXGroupListReq *req = [[RTCXGroupListReq alloc] init];
req.pageNo = 1;
req.pageSize = 10;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[self.tableView.mj_header endRefreshing];
NSString *jsonStr = [((RTCXGroupListRsp *)data).items iotyy_modelToJSONString];
weakSelf.dataArray = [NSArray iotyy_modelArrayWithClass:[GroupModel class] json:jsonStr];
[weakSelf.tableView.hwhd_rowArray addObjectsFromArray:weakSelf.dataArray];
[weakSelf.tableView reloadData];
} onError:^(NSError * _Nullable error) {
[self.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
添加设备到分组
RTCXGroupAddDeviceReq *req = [[RTCXGroupAddDeviceReq alloc] init];
req.groupId = self.groupInfo.groupId;
req.iotIdList = iotIds;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupAddDeviceWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf.navigationController popViewControllerAnimated:YES];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
分组中删除设备
RTCXGroupDeleteDeviceReq *req = [[RTCXGroupDeleteDeviceReq alloc] init];
req.groupId = self.groupInfo.groupId;
req.iotIdList = iotIds;
[RTCXDeviceService(RTCXDeviceGroupProtocol) groupDeleteDeviceWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf rightBtnOnClick:self.rightBtn];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];