移动门户集成客服和即时通讯功能

一、集成步骤

 按照神州泰岳提供的“即时通讯及机器人SDK接口规范”文档的集成步骤,添加相关SDK、第三方库、系统库到移动门户app中。

IM提供的SDK如下图:



需要的第三方库:


需要添加的系统库在baseapp中都已添加。

二、接口调用

1、注册融云接口

在appdelegate中调用该方法。

 //在线客服,注册账户
 [[UltraManager shareManager]registRongClound];

2、连接注册接口

在app登录界面和手势界面,本app登录接口调用成功后,调用该连接注册接口。

说明:

     a.第一个参数为注册到融云的id,应该传本app的唯一登陆标识。

     b.连接融云账号成功后,才可跳转到主页。

调用:

//连接融云账户,连接结果loginRongIMSuccess方法返回,成功后跳转
[[UltraManager shareManager] connectRongClound:g_staffId anduserName:g_userName andHeadUrl:t_loginInfo.iconImage];
[UltraManager shareManager].delegate = self;
代理实现:
#pragma mark - UlrapowerDelegate
-(void)loginRongIMSuccess:(BOOL)Result{
    dispatch_async(dispatch_get_main_queue(), ^{
         [self.progress dismiss];
        if (Result) {
            if ([[SessionStorage getItemWithKey:@"e_open"] isEqualToString:@"1"]) {
                [self handleMessage];
                return;
            }
            [self jump];
            
        }else{
            UIAlertView * view = [[UIAlertView alloc]initWithTitle:@"提示" message:@"融云登陆失败" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [view show];
        }
        
    });
}

3、判断连接状态接口

说明:

   a.主要用于处理被迫下线功能,一个融云账号同时只能在一个终端登陆。

   b.当用户在其他设备登陆返回状态为 ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT = 6

   c.处理被迫下线的逻辑,弹出提示框,提示用户重新登录。


调用:

 //监听状态
 [RCIM sharedRCIM].connectionStatusDelegate = self;

代理:



4、实现消息列表界面

(1)viewcontroller继承RCConversationListViewController,定制conversationListTableView的位置和headerview

   //设置会话列表所要显示的会话类型
    [self setDisplayConversationTypes:@[
                                        @(ConversationType_PRIVATE),
                                        @(ConversationType_DISCUSSION),
                                        @(ConversationType_GROUP),
                                        @(ConversationType_SYSTEM),
                                        @(ConversationType_CUSTOMERSERVICE)
                                        ]];
    
    //设置导航栏和底部选项卡,都是和平台实现方式一样
    [self setUI];
  
    [self setHeaderView];
    self.conversationListTableView.tableHeaderView = self.uiWhitePadClass_bigHeaderView;
    //去除多余线
    self.conversationListTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
#pragma mark - SZTY SDK

/*!
 点击会话列表中Cell的回调
 
 @param conversationModelType   当前点击的会话的Model类型
 @param model                   当前点击的会话的Model
 @param indexPath               当前会话在列表数据源中的索引值
 
 @discussion 您需要重写此点击事件,跳转到指定会话的会话页面。
 如果点击聚合Cell进入具体的子会话列表,在跳转时,需要将isEnteredToCollectionViewController设置为YES。
 */
-(void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath{
   
    self.navigationController.navigationBar.hidden =NO;
    if (model.conversationModelType == 3) {
        //如果是自定义类型
        ZHPReportChatVC *robot = [ZHPReportChatVC new];
        robot.chat = [ChatViewController new];
        robot.chat.groupDelegate=self;
        _chat = robot.chat;
        robot.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:robot animated:YES];
        NSLog(@"自定义会话点击事件");
        
    }else{
        
        _chat = [ChatViewController new];
        _chat.groupDelegate = self;
        _chat.targetId = model.targetId;
        _chat.conversationType = model.conversationType;
        _chat.title =model.conversationTitle;
        _chat.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_chat animated:YES];
    }
   
    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadbadgeValue" object:nil];
    
}

/*!
 即将加载列表数据源的回调
 
 @param dataSource      即将加载的列表数据源(元素为RCConversationModel对象)
 @return                修改后的数据源(元素为RCConversationModel对象)
 
 @discussion 您可以在回调中修改、添加、删除数据源的元素来定制显示的内容,会话列表会根据您返回的修改后的数据源进行显示。
 数据源中存放的元素为会话Cell的数据模型,即RCConversationModel对象。
 */
-(NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource{
    
//    for (int i = 0; i<3; i++) {
//        RCConversationModel *model = [[RCConversationModel alloc]init];
//        model.conversationModelType = 3;
//        model.targetId = @(i).stringValue;
//        //        [dataSource addObject:model];
//        [dataSource insertObject:model atIndex:i];
//    }
//
    return dataSource;
    
    
}

/*!
 左滑删除自定义会话时的回调
 
 @param tableView       当前TabelView
 @param editingStyle    当前的Cell操作,默认为UITableViewCellEditingStyleDelete
 @param indexPath       该Cell对应的会话Cell数据模型在数据源中的索引值
 
 @discussion 自定义会话Cell在删除时会回调此方法,您可以在此回调中,定制删除的提示UI、是否删除。
 如果确定删除该会话,您需要在调用RCIMClient中的接口删除会话或其中的消息,
 并从conversationListDataSource和conversationListTableView中删除该会话。
 */
- (void)rcConversationListTableView:(UITableView *)tableView
                 commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
                  forRowAtIndexPath:(NSIndexPath *)indexPath{
    RCConversationModel *model = self.conversationListDataSource[indexPath.row];
    [self.conversationListDataSource removeObject:model];
    [self.conversationListTableView reloadData];
}

(2)点击客服跳转到机器人界面

//点击客服
- (void)uiWhitePadClass_4xv7tiOnclick:(UITapGestureRecognizer*)recognizer{
   
    self.navigationController.navigationBar.hidden =NO;
    
    ZHPReportChatVC *robot = [ZHPReportChatVC new];
    robot.chat = [ChatViewController new];
    robot.chat.groupDelegate=self;
    _chat = robot.chat;
    robot.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:robot animated:YES];

}
(3)设置未读消息数

     需要在该uibox添加通知。获取未读数后,更新界面和IconBadge

//发送通知是在SZTYSDK里面,有新消息,就会发送这个通知
 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reloadbadgeValue) name:@"reloadbadgeValue" object:nil];
-(void)reloadbadgeValue{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //获取待办数目
        int t_countInt = 0;
        t_countInt = g_messageCount;
        
       
        
        if (t_countInt == 0) {
            [self.uiWhitePadClass_rljfbb setHidden:YES];
        } else if (t_countInt > 0 && t_countInt < 99) {
            [self.uiWhitePadClass_rljfbb setHidden:NO];
            self.uiLabelClass_ctnglt.text = [NSString stringWithFormat:@"%d",t_countInt];
        } else {
            [self.uiWhitePadClass_rljfbb setHidden:NO];
            self.uiLabelClass_ctnglt.text = @"99+";
           
        }
        
        
        //获取消息数目
        NSInteger unreadNum =  [[UltraManager shareManager] ureadNum];
        //总消息数目
        if (unreadNum<0) {
            t_countInt = t_countInt + 0;
        }else
        {
            t_countInt = t_countInt + unreadNum;
        }
        
        if (t_countInt == 0) {
            [self.uiWhitePadClass_s4klo2 setHidden:YES];
        } else if (t_countInt > 0 && t_countInt < 99) {
            [self.uiWhitePadClass_s4klo2 setHidden:NO];
            self.uiLabelClass_z1jcml.text = [NSString stringWithFormat:@"%d",t_countInt];
        } else {
            [self.uiWhitePadClass_s4klo2 setHidden:NO];
            self.uiLabelClass_z1jcml.text = @"99+";
            
        }
        
        [UIApplication sharedApplication].applicationIconBadgeNumber = t_countInt;
        
    });
    
}

(4)添加联系人功能

  IM提供代理:

#import <RongIMKit/RongIMKit.h>
@protocol addOrdelegateMemberDelegate <NSObject>
//点击右上角通讯录按钮
-(void)didClickGroupBtn:(NSMutableArray* )perpsons;
//加群的返回结果 YES 代表请求成功 NO 代表请求失败
-(void)addOrdelegateMember:(BOOL)Result;

@end

需要在消息列表界面,遵循协议并实现协议方法。展示选择联系人的界面是由移动开发平台开发,将添加人员传给代理方法。

三、实现效果


    


 

猜你喜欢

转载自blog.csdn.net/weixin_41906828/article/details/80052895
今日推荐