Mobile portal integrates customer service and instant messaging

1. Integration steps

 According to the integration steps of the "Instant Messaging and Robot SDK Interface Specification" document provided by Shenzhou Taiyue, add relevant SDKs, third-party libraries, and system libraries to the mobile portal app.

The SDK provided by IM is as follows:



Required third-party libraries:


The system libraries that need to be added have been added in baseapp.

2. Interface call

1. Register the Rongyun interface

Call this method in appdelegate.

//Online customer service, register account
 [[UltraManager shareManager]registRongClound];

2. Connect to the registration interface

In the app login interface and gesture interface, after the app login interface is successfully called, the connection registration interface is called.

illustrate:

     a. The first parameter is the id registered to Rongyun, which should pass the unique login ID of this app.

     b. After connecting to the Rongyun account successfully, you can jump to the homepage.

transfer:

//Connect to the Rongyun account, the connection result loginRongIMSuccess method returns, and jumps after success
[[UltraManager shareManager] connectRongClound:g_staffId anduserName:g_userName andHeadUrl:t_loginInfo.iconImage];
[UltraManager shareManager].delegate = self;
Proxy implementation:
#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:@"Prompt" message:@"Rongyun login failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [view show];
        }
        
    });
}

3. Determine the connection status interface

illustrate:

   a. It is mainly used to deal with the forced offline function. One Rongyun account can only log in to one terminal at the same time.

   b. When the user logs in on another device, the return status is  ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT =  6

   c. Handle the logic of being forced to go offline, and pop up a prompt box to prompt the user to log in again.


transfer:

//listen state
 [RCIM sharedRCIM].connectionStatusDelegate = self;

acting:



4. Implement the message list interface

(1) viewcontroller inherits RCConversationListViewController and customizes the position and headerview of conversationListTableView

   //Set the session type to be displayed in the session list
    [self setDisplayConversationTypes:@[
                                        @(ConversationType_PRIVATE),
                                        @(ConversationType_DISCUSSION),
                                        @(ConversationType_GROUP),
                                        @(ConversationType_SYSTEM),
                                        @(ConversationType_CUSTOMERSERVICE)
                                        ]];
    
    //Set the navigation bar and bottom tabs, which are the same as the platform implementation
    [self setUI];
  
    [self setHeaderView];
    self.conversationListTableView.tableHeaderView = self.uiWhitePadClass_bigHeaderView;
    // remove extra lines
    self.conversationListTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
#pragma mark - SZTY SDK

/*!
 Click the callback of the Cell in the session list
 
 @param conversationModelType Model type of the currently clicked conversation
 @param model Model of the currently clicked session
 @param indexPath The index value of the current session in the list data source
 
 @discussion You need to override this click event to jump to the session page of the specified session.
 If you click the aggregated Cell to enter the specific sub-session list, you need to set isEnteredToCollectionViewController to YES when jumping.
 */
- (void) onSelectedTableRow: (RCConversationModelType) conversationModelType conversationModel: (RCConversationModel *) model atIndexPath: (NSIndexPath *) indexPath {
   
    self.navigationController.navigationBar.hidden =NO;
    if (model.conversationModelType == 3) {
        //if it is a custom type
        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(@"Custom session click event");
        
    }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];
    
}

/*!
 Callback for about to load list data source
 
 @param dataSource The list data source to be loaded (the element is the RCConversationModel object)
 @return the modified data source (the element is the RCConversationModel object)
 
 @discussion You can modify, add, delete elements of the data source in the callback to customize what is displayed, and the session list will be displayed based on the modified data source you return.
 The element stored in the data source is the data model of the session Cell, that is, the RCConversationModel object.
 */
-(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;
    
    
}

/*!
 Callback when left swipe to delete custom session
 
 @param tableView current TabelView
 @param editingStyle The current Cell operation, the default is UITableViewCellEditingStyleDelete
 @param indexPath The index value of the session Cell data model corresponding to the Cell in the data source
 
 @discussion The custom session Cell will call back this method when it is deleted. In this callback, you can customize the delete prompt UI and whether to delete it.
 If you are sure to delete the session, you need to delete the session or the messages in it by calling the interface in RCIMClient,
 And remove that session from conversationListDataSource and 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) Click on customer service to jump to the robot interface

//click on customer service
- (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) Set the number of unread messages

     Need to add notification in this uibox. After getting unreads, update the interface and IconBadge

//Send notification is in SZTYSDK, if there is a new message, this notification will be sent
 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reloadbadgeValue) name:@"reloadbadgeValue" object:nil];
-(void)reloadbadgeValue{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //Get the number of to-dos
        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+";
           
        }
        
        
        // get the number of messages
        NSInteger unreadNum =  [[UltraManager shareManager] ureadNum];
        //Total number of messages
        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) Add contact function

  IM provides proxy:

#import <RongIMKit/RongIMKit.h>
@protocol addOrdelegateMemberDelegate <NSObject>
//Click the address book button in the upper right corner
-(void)didClickGroupBtn:(NSMutableArray* )perpsons;
//The return result of adding a group is YES means the request is successful NO means the request fails
-(void)addOrdelegateMember:(BOOL)Result;

@end

You need to follow the protocol and implement the protocol method in the message list interface. The interface that shows the selection of contacts is developed by the mobile development platform, and the add person is passed to the delegate method.

3. Realize the effect


    


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324812931&siteId=291194637