开启客服消息的轮询请求

业务场景

用于开始客服消息监听的心跳请求,默认不开启,开启后会周期性回调上述接口返回客服消息状态。

详细业务说明请看客服-客服消息的轮询请求

注意事项:

  • 登录成功后调用
  • 重复调用无效,最多只有一个心跳在监听
  • 获取客服消息需要角色 ID、角色名称和服务器 ID 等参数,因此当用户退出角色后需停止心跳监听

流程说明

接口介绍

/**
 * 开启客服消息的轮询请求
 *
 * @param CustomerServiceMsgConfig config   轮询参数
 */

- (void)startCustomerServiceMsgHeartbeat:(CustomerServiceMsgConfig *)config;

调用示例

// 客服消息回调通知【建议初始化前调用】
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(registerCustomerServiceMsg:) name:NOTIFICATION_GETMESSAGE_SUCCESS object:nil];

// 开启接口调用
CustomerServiceMsgConfig *config = [[CustomerServiceMsgConfig alloc]init];
config.intervalSeconds = 60; // 心跳间隔: 默认60秒, 且最小值为60秒
[[SDKManager getInstance] startCustomerServiceMsgHeartbeat:config];

// 回调方法
- (void)registerCustomerServiceMsg:(NSNotification *)notif
{
    NSDictionary *CustomerServiceMsgData = notif.userInfo;
    BOOL hasUnreadMsg = [CustomerServiceMsgData[KEY_MESSAGE_STATUS] boolValue];
    NSString *openId = CustomerServiceMsgData[KEY_OPENID];
    // 注意判断是否是当前用户的消息, 某些场景如切换账号短暂期间可能会收到上一次登录用户的消息
    if (self.signStr != nil && [self.signStr isEqualToString:openId]) {
        NSLog(@"收到客服消息:%d", unread);
        // 显示红点提示
    }
}

参数说明

入参

CustomerServiceMsgConfig config

参数名称类型说明备注
intervalSecondsNSInteger轮询间隔时间,单位是秒,默认 60 秒必传

出参

CustomerServiceMsgData data

参数名称类型说明备注
openIdNSString当前用户 openId
hasUnreadMsgBOOL是否有未读消息

错误码

FAQ