自定义房间属性
RCRTCRoom 类提供音视频房间的扩展属性功能。在音视频房间中,您可以设置、获取和删除扩展属性。
设置房间属性
接口原型
Objective C
- (void)setAttribute:(NSString *)attributeValue
forKey:(NSString *)key
message:(nullable RCMessageContent *)message
completion:(nullable RCRTCOperationCallback)completion;
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
attributeValue | NSString | 是 | 属性值 |
key | NSString | 是 | 属性名称 |
message | RCMessageContent | 否 | 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息,可以通过自定义消息通知其他端有新属性已经设置 |
completion | RCRTCOperationCallback | 否 | 设置完成回调 block |
代码示例
Objective C
#import <RongRTCLib/RongRTCLib.h>
[[RCRTCEngine sharedInstance].room setAttribute:@"属性 Value 值"
forKey:@"属性 Key 值"
message:message
completion:^(BOOL isSuccess, RCRTCCode code) {
}];
获取房间属性
接口原型
Objective C
- (void)getAttributes:(NSArray<NSString *> *)attributeKeys
completion:(nullable RCRTCAttributeOperationCallback)completion;
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
attributeKeys | NSArray | 是 | 属性 Key 值列表 |
completion | RCRTCAttributeOperationCallback | 否 | 查询结果的回调 block |
代码示例
Objective C
[[RCRTCEngine sharedInstance].room getAttributes:@[@"属性 Key 值"]
completion:^(BOOL isSuccess, RCRTCCode code, NSDictionary * _Nullable attr) {
}];
删除属性
接口原型
Objective C
- (void)deleteAttributes:(NSArray<NSString *> *)attributeKeys
message:(nullable RCMessageContent *)message
completion:(nullable RCRTCOperationCallback)completion;
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
attributeKeys | NSArray | 是 | 属性 Key 值列表 |
message | RCMessageContent | 否 | 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息 |
completion | RCRTCOperationCallback | 否 | 删除完成回调 block |
代码示例
Objective C
[[RCRTCEngine sharedInstance].room deleteAttributes:@[@"Key 值"]
message:deleteMessage
completion:^(BOOL isSuccess, RCRTCCode code) {
}];
属性变化回调
在设置和删除自定义房间属性时,房间内的其他用户可通过 RCRTCRoomEventDelegate 的代理方法,回调接收自定义的房间属性消息 RCMessage。
接口原型
Objective C
- (void)didReceiveMessage:(RCMessage *)message;
参数说明
参数名 | 类型 | 是否必填 | 说明 |
---|---|---|---|
message | RCMessage | 是 | 接收到其他人发送到 room 里的消息体,包括自定义房间属性变化消息 |
代码示例
Objective C
// 设置房间事件代理
[RCRTCEngine sharedInstance].room.delegate = self;
// 实现代理方法
- (void)didReceiveMessage:(RCMessage *)message {
}