设备分组
更新时间:2026-08-11 10:45:54
// 导入设备管理SDK头文件
#import <RTCXDeviceCenter/RTCXDeviceCenter.h>
对用户下的设备进行家庭管理与分组管理,家庭组下可以创建多个设备分组
@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;
/**
* 创建家庭
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)homeCreateWithReq:(nonnull RTCXHomeCreateReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 删除家庭
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)homeDeleteWithReq:(nonnull RTCXHomeDeleteReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 更新家庭信息
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)homeUpdateWithReq:(nonnull RTCXHomeUpdateReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 家庭列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)homeListWithReq:(nonnull RTCXHomeListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
@end
使用 RTCXDeviceSDK 单例宏对象调用示例如下:
创建设备分组
RTCXGroupCreatReq *req = [[RTCXGroupCreatReq alloc] init];
req.name = self.groupName;
req.iotIdList = iotIds;
if (homeId > 0) {
// 如果设置homeId,将在该家庭组下创建设备分组
req.homeId = [NSNumber numberWithInteger:homeId];
}
[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;
if (self.homeInfoModel) {
// 如果设置homeId,将查询该家庭组下的设备分组列表
req.homeId = [NSNumber numberWithInteger:self.homeInfoModel.homeId];
}
[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]]];
}];
创建家庭
NSMutableArray *groupNames = [[NSMutableArray alloc] initWithCapacity:0];
[self.selectedDataArray enumerateObjectsUsingBlock:^(HomeGroupModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.name) {
RTCXGroupCreatReq *groupReq = [[RTCXGroupCreatReq alloc] init];
groupReq.name = obj.name;
[groupNames addObject:groupReq];
}
}];
__weak typeof(self) weakSelf = self;
RTCXHomeCreateReq *req = [[RTCXHomeCreateReq alloc] init];
req.name = name;
if (groupNames && groupNames.count > 0) {
req.groupList = groupNames;
}
[RTCXDeviceService(RTCXDeviceGroupProtocol) homeCreateWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf hideLoadingView];
[weakSelf showToast:NSLocalizedString(@"创建成功", nil)];
[weakSelf.navigationController popViewControllerAnimated:YES];
} onError:^(NSError * _Nullable error) {
[weakSelf hideLoadingView];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
删除家庭
RTCXHomeDeleteReq *req = [[RTCXHomeDeleteReq alloc] init];
req.homeId = model.homeId;
[RTCXDeviceService(RTCXDeviceGroupProtocol) homeDeleteWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf getHomeList];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
家庭列表
__weak typeof(self) weakSelf = self;
RTCXHomeListReq *req = [[RTCXHomeListReq alloc] init];
req.pageNo = 1;
req.pageSize = 20;
[RTCXDeviceService(RTCXDeviceGroupProtocol) homeListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf.tableView.mj_header endRefreshing];
NSString *jsonStr = [((RTCXHomeListRsp *)data).items iotyy_modelToJSONString];
weakSelf.dataArray = [NSArray iotyy_modelArrayWithClass:[HomeModel class] json:jsonStr];
[weakSelf.tableView reloadData];
} onError:^(NSError * _Nullable error) {
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
更新家庭信息
RTCXHomeUpdateReq *req = [[RTCXHomeUpdateReq alloc] init];
req.homeId = model.homeId;
req.name = name;
[RTCXDeviceService(RTCXDeviceGroupProtocol) homeUpdateWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf getHomeList];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];