How to Send Custom Messages with the iOS Live Streaming SDK
Updated: 2023-03-26 20:05:59
Problem Description
After integrating the Polyv iOS Live Streaming SDK into your project, you may need to send custom messages to enhance interactivity or implement business logic related to your own system. The Polyv Live Streaming SDK's chat room provides an API for sending custom messages. See the solution below for details.
Solution
The PLVChatroomPresenter class provides APIs for sending and receiving various types of messages, and encapsulates the messages into data models for return. The specific interface definitions are as follows:
- Sending Custom Messages
/// 发送自定义消息
/// @param event 自定义消息event字段
/// @param data 自定义消息data字段
/// @param tip 自定义消息tip字段
/// @param emitMode 自定义消息emitMode字段(0-发送给所有人,1-发送给所有人除了自己,2-只发送给自己)
/// @return 消息数据模型, 发送失败时,返回nil
- (PLVChatModel * _Nullable)sendCustomMessageWithEvent:(NSString *)event
data:(NSDictionary *)data
tip:(NSString * _Nullable)tip
emitMode:(int)emitMode;
- Receiving Custom Messages
/// 其他自定义监听事件回调
/// @param event 监听事件类型
/// @param subEvent 返回的EVENT类型
/// @param jsonString 返回的数据json原格式
/// @param object 返回数据转换成的OC格式,为NSArray或NSDictionary
- (void)socketMananger_didReceiveEvent:(NSString *)event
subEvent:(NSString *)subEvent
json:(NSString *)jsonString
jsonObject:(id)object;
