设备分享
更新时间:2024-12-11 19:02:54
用户之间分享设备
@protocol RTCXDeviceShareProtocol <NSObject>
/**
* 生成分享用的二维码(30min有效)
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)generateShareQrCodeWithReq:(nonnull RTCXGeneralShareQrcodeReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 通过扫描二维码绑定设备(分享设备)
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)deviceBindByScanShareQrCodeWithReq:(nonnull RTCXScanShareQrCodeBindReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 设备分享给指定的用户
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)deviceShareWithReq:(nonnull RTCXDeviceShareReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 获取共享通知列表
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)getShareDeviceNoticeListWithReq:(nonnull RTCXDeviceShareNoticeListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 被分享者同意或拒绝分享
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)confirmShareWithReq:(nonnull RTCXConfirmShareReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 发起者取消分享
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)cancelShareWithReq:(nonnull RTCXCancelShareReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 查询设备分享记录
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)getDeviceShareRecordWithReq:(nonnull RTCXDeviceShareRecordReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 分享权限修改
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)setPermissionListWithReq:(nonnull RTCXSetPermissionListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 查询用户下设备当前被分享用户(初始化和接受状态)
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)getDeviceShareUserListWithReq:(nonnull RTCXDeviceShareUserListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
/**
* 查询用户下设备的分享数量(初始化和接受状态)
*
* @param req 请求参数对象
* @param onSuccess 成功回调
* @param onError 失败回调
*/
- (void)getDeviceShareCountListWithReq:(nonnull RTCXDeviceShareCountListReq *)req onSuccess:(nullable RTCXDeviceMgrOnSuccess)onSuccess onError:(nullable RTCXDeviceMgrOnError)onError;
@end
使用 RTCXDeviceSDK 单例宏对象调用示例如下:
生成分享用的二维码
RTCXGeneralShareQrcodeReq *req = [[RTCXGeneralShareQrcodeReq alloc] init];
req.iotIdList = self.iotIds;
req.permissionList = permissionArr;
[RTCXDeviceService(RTCXDeviceShareProtocol) generateShareQrCodeWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
NSDictionary *responseDic = data;
if (responseDic) {
UIImage *qrcodeImg = [QRCodeGenerator generateQRCodeWithData:[responseDic iotyy_modelToJSONString] imageViewWidth:300];
weakSelf.qrCodeImage = qrcodeImg;
[weakSelf creatShareQrcodeView];
}
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
通过扫描二维码绑定设备
RTCXScanShareQrCodeBindReq *req = [[RTCXScanShareQrCodeBindReq alloc] init];
req.qrKey = qrKey;
[RTCXDeviceService(RTCXDeviceShareProtocol) deviceBindByScanShareQrCodeWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
MyDeviceListViewController *myDeviceListVc = (MyDeviceListViewController*)[[weakSelf.listContainerView validListDict] objectForKey:@(0)];
[myDeviceListVc refreshData];
ShareDeviceListViewController *shareDeviceList = (ShareDeviceListViewController*)[[weakSelf.listContainerView validListDict] objectForKey:@(1)];
[shareDeviceList refreshData];
} onError:^(NSError * _Nullable error) {
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
设备分享给指定的用户
RTCXDeviceShareReq *req = [[RTCXDeviceShareReq alloc] init];
req.iotIdList = self.iotIds;
req.accountAttr = self.textField.text;
req.accountAttrType = @"MOBILE";
req.permissionList = permissionArr;
[RTCXDeviceService(RTCXDeviceShareProtocol) deviceShareWithReq: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]]];
}];
获取分享通知列表
RTCXDeviceShareNoticeListReq *req = [[RTCXDeviceShareNoticeListReq alloc] init];
req.pageNo = 1;
req.pageSize = 200;
req.groupBy = @"BATCH";
[RTCXDeviceService(RTCXDeviceShareProtocol) getShareDeviceNoticeListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[self.tableView.mj_header endRefreshing];
NSString *jsonStr = [((RTCXShareNoticeListRsp *)data).data iotyy_modelToJSONString];
weakSelf.shareNotyList = [NSArray iotyy_modelArrayWithClass:[ShareDeviceListModel class] json:jsonStr];
[weakSelf.tableView.hwhd_rowArray addObjectsFromArray:weakSelf.shareNotyList];
[weakSelf.tableView reloadData];
} onError:^(NSError * _Nullable error) {
[self.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
被分享者同意或拒绝分享
RTCXConfirmShareReq *req = [[RTCXConfirmShareReq alloc] init];
req.recordIdList = @[@(recordId)];
req.agree = agree;
[RTCXDeviceService(RTCXDeviceShareProtocol) confirmShareWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf stopLoading];
[self getShareNotifyList];
} onError:^(NSError * _Nullable error) {
[weakSelf stopLoading];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
发起者取消分享
RTCXCancelShareReq *req = [[RTCXCancelShareReq alloc] init];
req.recordIdList = @[@(recordId)];
[RTCXDeviceService(RTCXDeviceShareProtocol) cancelShareWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf stopLoading];
[self getShareNotifyList];
} onError:^(NSError * _Nullable error) {
[weakSelf stopLoading];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
查询设备分享记录
RTCXDeviceShareRecordReq *req = [[RTCXDeviceShareRecordReq alloc] init];
req.pageNo = 1;
req.pageSize = 200;
req.batchId = self.model.batchId;
[RTCXDeviceService(RTCXDeviceShareProtocol) getDeviceShareRecordWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[self.tableView.mj_header endRefreshing];
NSString *jsonStr = [((RTCXDeviceShareRecordListRsp *)data).data iotyy_modelToJSONString];
weakSelf.shareNotyList = [NSArray iotyy_modelArrayWithClass:[ShareDeviceListModel class] json:jsonStr];
[weakSelf.tableView.hwhd_rowArray addObjectsFromArray:weakSelf.shareNotyList];
[weakSelf.tableView reloadData];
} onError:^(NSError * _Nullable error) {
[self.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
分享权限修改
RTCXSetPermissionListReq *req = [[RTCXSetPermissionListReq alloc] init];
req.recordId = self.model.recordId;
req.permissionList = permissionArr;
[RTCXDeviceService(RTCXDeviceShareProtocol) setPermissionListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[weakSelf stopLoading];
[weakSelf.navigationController popViewControllerAnimated:YES];
} onError:^(NSError * _Nullable error) {
[weakSelf stopLoading];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
查询用户下设备当前被分享用户(初始化和接受状态)
RTCXDeviceShareUserListReq *req = [[RTCXDeviceShareUserListReq alloc] init];
req.pageNo = 1;
req.pageSize = 200;
req.iotId = self.iotId;
[RTCXDeviceService(RTCXDeviceShareProtocol) getDeviceShareUserListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[self.tableView.mj_header endRefreshing];
NSString *jsonStr = [((RTCXDeviceShareUserListRsp *)data).items iotyy_modelToJSONString];
weakSelf.shareNotyList = [NSArray iotyy_modelArrayWithClass:[ShareDeviceListModel class] json:jsonStr];
[weakSelf.tableView.hwhd_rowArray addObjectsFromArray:weakSelf.shareNotyList];
[weakSelf.tableView reloadData];
if (weakSelf.shareNotyList.count <= 0) {
[weakSelf showToast:@"该设备未分享给任何人"];
}
} onError:^(NSError * _Nullable error) {
[self.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];
查询用户下设备的分享数量(初始化和接受状态)
RTCXDeviceShareCountListReq *req = [[RTCXDeviceShareCountListReq alloc] init];
req.pageNo = 1;
req.pageSize = 100;
[RTCXDeviceService(RTCXDeviceShareProtocol) getDeviceShareCountListWithReq:req onSuccess:^(id _Nullable data, id _Nullable rawData) {
[self.tableView.mj_header endRefreshing];
NSInteger maxShareCount = ((RTCXDeviceShareCountListRsp *)data).maxShareCount;
NSString *jsonStr = [((RTCXDeviceShareCountListRsp *)data).items iotyy_modelToJSONString];
weakSelf.devicelist = [NSArray iotyy_modelArrayWithClass:[MyDeviceListModel class] json:jsonStr];
[weakSelf.devicelist enumerateObjectsUsingBlock:^(MyDeviceListModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.maxShareCount = maxShareCount;
}];
[weakSelf.tableView.hwhd_rowArray addObjectsFromArray:weakSelf.devicelist];
[weakSelf.tableView reloadData];
} onError:^(NSError * _Nullable error) {
[self.tableView.mj_header endRefreshing];
[weakSelf showToast:[NSString stringWithFormat:@"%ld : %@",error.code,error.userInfo[NSLocalizedFailureReasonErrorKey]]];
}];