iOS--融雲即時通訊的使用(推送、聊天和會話列表的頭像和暱稱)

集成剛說完,這裏接直接說使用吧緩存

1、初始化服務器

導入頭文件 微信

#import <RongIMKit/RongIMKit.h>

#import <RongIMLib/RongIMLib.h>

初始化網絡

//AppKey要對應,必定注意開發環境和生產環境對應的AppKey
[[RCIM sharedRCIM] initWithAppKey:RONGCLOUDAPPKEY];

鏈接服務器:融雲提供的connectWithToken:success:error:tokenIncorrect: 方法,須要傳入融雲的token值,這個token值是在登陸本身服務器時,後臺所傳過來的,同時傳過來的數據中要保存融雲的userId,頭像和暱稱,這些在會話列表和聊天界面都要用到。app

//若是存在token,直接進行鏈接,不存在就訪問本身的服務器,拿到token以後再次進行鏈接 
NSString *ryToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"rytoken"];
    NSLog(@"進入首頁ryToken:%@",ryToken);
    if(ryToken){
        [[RCIM sharedRCIM] connectWithToken: ryToken    success:^(NSString *userId) {
            NSLog(@" 微信 登錄登錄成功。當前登陸的用戶ID:%@", userId);
        } error:^(RCConnectErrorCode status) {
            NSLog(@"微信 登錄登錄的錯誤碼爲:%lu", status);
        } tokenIncorrect:^{
            //token過時或者不正確。
            //若是設置了token有效期而且token過時,請從新請求您的服務器獲取新的token
            //若是沒有設置token有效期卻提示token錯誤,請檢查您客戶端和服務器的appkey是否匹配,還有檢查您獲取token的流程。
            NSLog(@"微信 登錄token錯誤");
        }];
    }else{
        
        //訪問本身服務器,獲取融雲token值
        [self getRongCloudToken];
        
    }

還有一些其餘的添加:curl

//是否在發送的全部消息中攜帶當前登陸的用戶信息
    [RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
    
    RCUserInfo *_currentUserInfo =
    [[RCUserInfo alloc] initWithUserId:[[NSUserDefaults standardUserDefaults] objectForKey:@"ryuid"] name:[[NSUserDefaults standardUserDefaults] objectForKey:@"nickname"] portrait:[[NSUserDefaults standardUserDefaults] objectForKey:@"headimgurl"]];
    
    [RCIM sharedRCIM].currentUserInfo = _currentUserInfo;

    
    //設置日誌級別  輸出錯誤、警告和通常的日誌
    [RCIMClient sharedRCIMClient].logLevel = RC_Log_Level_Info;
    
   //開啓用戶信息和羣組信息的持久化
    [RCIM sharedRCIM].enablePersistentUserInfoCache = YES;
    //設置用戶信息源和羣組信息源(這個須要本身實現,寫成單例就能夠,下面補充)
    [RCIM sharedRCIM].userInfoDataSource = HYNRCDData;
    [RCIM sharedRCIM].groupInfoDataSource = HYNRCDData;
    
    //是否在發送的全部消息中攜帶當前登陸的用戶信息
    [RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
    
    
    //開啓消息撤回功能
    [RCIM sharedRCIM].enableMessageRecall = YES;
    
    //  設置頭像爲圓形
    [RCIM sharedRCIM].globalMessageAvatarStyle = RC_USER_AVATAR_CYCLE;
    [RCIM sharedRCIM].globalConversationAvatarStyle = RC_USER_AVATAR_CYCLE;
    // 設置優先使用WebView打開URL
    [RCIM sharedRCIM].embeddedWebViewPreferred = YES;
    
    
    //開啓多端未讀狀態同步
    [RCIM sharedRCIM].enableSyncReadStatus = YES;
    
    //設置顯示未註冊的消息
    //如:新版本增長了某種自定義消息,可是老版本不能識別,開發者能夠在舊版本中預先自定義這種未識別的消息的顯示
    [RCIM sharedRCIM].showUnkownMessage = YES;
    [RCIM sharedRCIM].showUnkownMessageNotificaiton = YES;

設置本身的數據源信息:HYNRCDataSource:async

//HYNRCDataSource.h文件
#import <Foundation/Foundation.h>
#import <RongIMKit/RongIMKit.h>

#define HYNRCDData [HYNRCDataSource shareInstance]
//遵照協議
@interface HYNRCDataSource : NSObject<RCIMUserInfoDataSource, RCIMGroupInfoDataSource>


+ (HYNRCDataSource *)shareInstance;


@end

//HYNRCDataSource.m文件

#import "HYNRCDataSource.h"

static HYNRCDataSource *_dataSource = nil;

@implementation HYNRCDataSource



+(HYNRCDataSource *)shareInstance
{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        
        _dataSource = [[[self class] alloc] init];
    });
    
    return _dataSource;
}

//獲取羣組信息
#pragma mark - RCIMUserInfoDataSource
- (void)getGroupInfoWithGroupId:(NSString *)groupId
                     completion:(void (^)(RCGroup *))completion {
    if ([groupId length] == 0)
        return;
    
//從本身的服務器中獲取羣的基本信息,而後傳到融雲的SDK中,在會話列表頁面就能夠顯示圈子的圖片和圈子的名字
    NSString *url = [NSString stringWithFormat:@"%@%@",NEW_BASEURL,GETGROUPINFO];
    NSDictionary *param = @{@"ry_gid":groupId};
    
    [[HTTPRequest sharedInstance] GET:url parameters:param succeed:^(id responseObject) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        
        if([dic[@"code"] isEqualToString:@"200"]){
            
            RCGroup *info = [[RCGroup alloc] init];
            info.groupId = groupId;
            info.groupName = dic[@"groupinfo"][@"gname"];
            info.portraitUri = dic[@"groupinfo"][@"picurl"];
                
            return completion(info);
            
        }
        
        
    } failure:^(NSError *error) {
        
        
        NSLog(@"獲取圈聊信息 失敗error:%@",error);
        
        
    }];
    
    
}

// 獲取用戶信息
#pragma mark - RCIMUserInfoDataSource
- (void)getUserInfoWithUserId:(NSString *)userId
                   completion:(void (^)(RCUserInfo *))completion {
    
    
  //  NSLog(@"getUserInfoWithUserId ----- %@", userId);
    RCUserInfo *user = [RCUserInfo new];
    if (userId == nil || [userId length] == 0) {
        user.userId = userId;
        user.portraitUri = @"";
        user.name = @"";
        completion(user);
        return;
    }
    //從本身的服務器中獲取單聊用戶的基本信息,而後傳到融雲的SDK中,在會話列表頁面就能夠顯示單聊的的頭像和名字


    if([userId isEqualToString: [[NSUserDefaults standardUserDefaults] objectForKey:@"ryuid"]]){
        
     //若是當前用戶信息是本身的信息,就傳入本身的基本信息   
        RCUserInfo *info = [[RCUserInfo alloc] initWithUserId:userId name:[[NSUserDefaults standardUserDefaults] objectForKey:@"nickname"] portrait:[[NSUserDefaults standardUserDefaults] objectForKey:@"headimgurl"]];
        
        NSLog(@"--------------RCUserInfo-----info:%@",info);

        //更新SDK中的用戶信息緩存(可保證用戶在更換頭像時,App的頭像能更換)
        [[RCIM sharedRCIM] refreshUserInfoCache:user withUserId:user.userId];
        return completion(info);
    }else{
        
        //若是當前用戶不是本身,就訪問本身服務器獲取用戶的基本信息,傳入SDK
        NSString *url = [NSString stringWithFormat:@"%@%@",NEW_BASEURL,GETUSERINFO];
        NSDictionary *param = @{@"user_ryid":userId};
        
        [[HTTPRequest sharedInstance] GET:url parameters:param succeed:^(id responseObject) {
            
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            if([dic[@"code"] isEqualToString:@"200"]){
                
                RCUserInfo *user = [[RCUserInfo alloc]init];
                user.userId = userId;
                user.name = dic[@"userinfo"][@"nickname"];
                user.portraitUri = dic[@"userinfo"][@"headimgurl"];
                
                
                
                return completion(user);
                
            }
            
            
        } failure:^(NSError *error) {
            
            
            NSLog(@"獲取用戶信息 失敗error:%@",error);
            
            
        }];
        
    }
}


@end

 

2、推送ide

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {



 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {

        //註冊推送, iOS 8
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];

    }
    //融雲即時通信

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessageNotification:) name:RCKitDispatchMessageNotification object:nil];



}

- (void)didReceiveMessageNotification:(NSNotification *)notification {
    NSNumber *left = [notification.userInfo objectForKey:@"left"];
    if ([RCIMClient sharedRCIMClient].sdkRunningMode ==
        RCSDKRunningMode_Background &&
        0 == left.integerValue) {
        int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[
                                                                           @(ConversationType_PRIVATE),@(ConversationType_GROUP)]];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [UIApplication sharedApplication].applicationIconBadgeNumber =
            unreadMsgCount;
            
  });
        
    }
}

//註冊用戶通知設置
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:
(UIUserNotificationSettings *)notificationSettings {
    // register to receive notifications
    [application registerForRemoteNotifications];
}

//將獲得的deviceToken傳給SDK
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
    //融雲推送
    NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""]
      stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" "
     withString:@""];
    [[RCIMClient sharedRCIMClient] setDeviceToken:token];
    
}


//註冊deviceToken失敗

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{
    
    NSLog(@"deviceToken-----error -- %@",error);
    
}

// APP進入後臺

- (void)applicationDidEnterBackground:(UIApplication*)application

{
    
    // 爲消息分享保存會話信息
    [self saveConversationInfoForMessageShare];
    
}

// APP將要從後臺返回

- (void)applicationWillEnterForeground:(UIApplication*)application

{
    
    if ([[RCIMClient sharedRCIMClient] getConnectionStatus] == ConnectionStatus_Connected) {
        // 插入分享消息
        [self insertSharedMessageIfNeed];
    }
}

//爲消息分享保存會話信息
- (void)saveConversationInfoForMessageShare {
    NSArray *conversationList = [[RCIMClient sharedRCIMClient] getConversationList:@[@(ConversationType_PRIVATE), @(ConversationType_GROUP)]];
    
    NSMutableArray *conversationInfoList = [[NSMutableArray alloc] init];
    if (conversationList.count > 0) {
        for (RCConversation *conversation in conversationList) {
            NSMutableDictionary *conversationInfo = [NSMutableDictionary dictionary];
            [conversationInfo setValue:conversation.targetId forKey:@"targetId"];
            [conversationInfo setValue:@(conversation.conversationType) forKey:@"conversationType"];
            if (conversation.conversationType == ConversationType_PRIVATE) {
                RCUserInfo * user = [[RCIM sharedRCIM] getUserInfoCache:conversation.targetId];
                [conversationInfo setValue:user.name forKey:@"name"];
                [conversationInfo setValue:user.portraitUri forKey:@"portraitUri"];
            }else if (conversation.conversationType == ConversationType_GROUP){
                RCGroup *group = [[RCIM sharedRCIM] getGroupInfoCache:conversation.targetId];
                [conversationInfo setValue:group.groupName forKey:@"name"];
                [conversationInfo setValue:group.portraitUri forKey:@"portraitUri"];
            }
            [conversationInfoList addObject:conversationInfo];
        }
    }
    NSURL *sharedURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.cn.rongcloud.im.share"];
    NSURL *fileURL = [sharedURL URLByAppendingPathComponent:@"rongcloudShare.plist"];
    [conversationInfoList writeToURL:fileURL atomically:YES];
    
    NSUserDefaults *shareUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.cn.rongcloud.im.share"];
    [shareUserDefaults setValue:[RCIM sharedRCIM].currentUserInfo.userId forKey:@"currentUserId"];
    [shareUserDefaults setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"UserCookies"] forKey:@"Cookie"];
    [shareUserDefaults synchronize];
}

//插入分享消息
- (void)insertSharedMessageIfNeed {
    NSUserDefaults *shareUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.cn.rongcloud.im.share"];
    
    NSArray *sharedMessages = [shareUserDefaults valueForKey:@"sharedMessages"];
    if (sharedMessages.count > 0) {
        for (NSDictionary *sharedInfo in sharedMessages) {
            RCRichContentMessage *richMsg = [[RCRichContentMessage alloc]init];
            richMsg.title = [sharedInfo objectForKey:@"title"];
            richMsg.digest = [sharedInfo objectForKey:@"content"];
            richMsg.url = [sharedInfo objectForKey:@"url"];
            richMsg.imageURL = [sharedInfo objectForKey:@"imageURL"];
            richMsg.extra = [sharedInfo objectForKey:@"extra"];
            //      long long sendTime = [[sharedInfo objectForKey:@"sharedTime"] longLongValue];
            //      RCMessage *message = [[RCIMClient sharedRCIMClient] insertOutgoingMessage:[[sharedInfo objectForKey:@"conversationType"] intValue] targetId:[sharedInfo objectForKey:@"targetId"] sentStatus:SentStatus_SENT content:richMsg sentTime:sendTime];
            RCMessage *message = [[RCIMClient sharedRCIMClient] insertOutgoingMessage:[[sharedInfo objectForKey:@"conversationType"] intValue] targetId:[sharedInfo objectForKey:@"targetId"] sentStatus:SentStatus_SENT content:richMsg];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"RCDSharedMessageInsertSuccess" object:message];
        }
        [shareUserDefaults removeObjectForKey:@"sharedMessages"];
        [shareUserDefaults synchronize];
    }
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    //融雲推送
    [[RCIMClient sharedRCIMClient] recordRemoteNotificationEvent:userInfo];
}

- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
    /**
     * 統計推送打開率3
     */
    [[RCIMClient sharedRCIMClient] recordLocalNotificationEvent:notification];
    
    //  //震動
    //  AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    //  AudioServicesPlaySystemSound(1007);
}

- (void)applicationWillResignActive:(UIApplication *)application {
    
    RCConnectionStatus status = [[RCIMClient sharedRCIMClient] getConnectionStatus];
    if (status != ConnectionStatus_SignUp) {
        int unreadMsgCount = [[RCIMClient sharedRCIMClient]
                              getUnreadCount:@[
                                               @(ConversationType_PRIVATE),
                                               @(ConversationType_GROUP)
                                               ]];
        application.applicationIconBadgeNumber = unreadMsgCount;
    }
}



- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:RCKitDispatchMessageNotification
     object:nil];
}

3、檢測融雲網絡狀態變化佈局

//當前用戶在其餘設備上登陸,此設備被踢下線
- (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status {
    if (status == ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"提示"
                              message:
                              @"您的賬號在別的設備上登陸,"
                              @"您被迫下線!"
                              delegate:nil
                              cancelButtonTitle:@"知道了"
                              otherButtonTitles:nil, nil];
        [alert show];
        
        //跳轉到本身的登陸頁面

        HYNLoginController *loginVC = [[HYNLoginController alloc] init];
        self.window.rootViewController = loginVC;
        
    }
    
}

 

4、聊天界面和會話列表post

1.聊天界面:

 作過環信,再作這個聊天界面,就至關簡單,建立一個繼承融雲聊界面RCConversationViewController的聊天控制器便可,如下代碼爲點擊私聊進入聊天界面

HYNRCChatViewController *chatVC = [[HYNRCChatViewController alloc] initWithConversationType:ConversationType_GROUP targetId:_ry_gid];
    chatVC.title = self.navigationItem.title;
    
     HYNNavigationController *nav = [[HYNNavigationController alloc] initWithRootViewController:chatVC];
    //標題
    chatVC.title = _dataSourDict[@"grpinfo"][@"gname"];
    
[self.navigationController pushViewController:chatController animated:YES];

如圖:

             

 

2.會話列表:要實現的界面,如圖

         

與聊天列表同樣,建立一個繼承融雲會話列表RCConversationListViewController的控制器,在這個界面中添加本身須要的UI佈局。

坑:融雲會話列表能夠繼承,可是可變性不大,如上圖需求,在使用環信時,UITableView能夠設置group屬性,而後建立2個section,section1爲本身的需求界面,section2爲聊天的會話列表;可是融雲不能夠,若是這樣佈局,那麼提供的 self.conversationListDataSource 數據源就爲空,沒有任何會話數據,這個問題融雲的技術給了回覆,說是不推薦這樣使用,給出的解決方法就是:把上面的本身須要的界面加載到表頭或者建立2個UITableView,二選一就直接加載到headerView上,這樣最簡單。

代碼:

//建立融雲聊天所須要的類型
- (id)init {
    self = [super init];
    if (self) {
        //設置要顯示的會話類型,可根據需求,這裏只實現了單聊和羣聊
        [self setDisplayConversationTypes:@[
                                            @(ConversationType_PRIVATE),
                                            @(ConversationType_GROUP),
                                            ]];
        
        //聚合會話類型
       // [self setCollectionConversationType:@[ @(ConversationType_SYSTEM) ]];
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //獲取傳聲筒未讀數
   // [self loadMessageCound];
    

     //消息的提示信息
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(receiveNeedRefreshNotification:)
     name:@"kRCNeedReloadDiscussionListNotification"
     object:nil];
    
    RCUserInfo *groupNotify = [[RCUserInfo alloc] initWithUserId:@"__system__"
                                                            name:@""
                                                        portrait:nil];
    [[RCIM sharedRCIM] refreshUserInfoCache:groupNotify withUserId:@"__system__"];
    
    [self updateBadgeValueForTabBarItem];
  
}

代碼:

//註銷通知
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"kRCNeedReloadDiscussionListNotification" object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GotoNextCoversation" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"RCDSharedMessageInsertSuccess" object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"RefreshConversationList" object:nil];
    //清除badge角標
     [self.tabBarController.tabBar hideBadgeOnItemIndex:1];
 
}

- (void)receiveNeedRefreshNotification:(NSNotification *)status {
    __weak typeof(&*self) __blockSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        if (__blockSelf.displayConversationTypeArray.count == 1 &&
            [self.displayConversationTypeArray[0] integerValue] ==
            ConversationType_DISCUSSION) {
            [__blockSelf refreshConversationTableViewIfNeeded];
        }
        
    });
}

 

代碼:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
     _titleArr= @[@"評論",@"點贊",@"同問",@"傳聲筒"];
     _userToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"userToken"];

   //設置表頭(本身的UI佈局)
   self.conversationListTableView.tableHeaderView = self.headerView;

    // 設置在NavigatorBar中顯示鏈接中的提示
    self.showConnectingStatusOnNavigatorBar = YES;
    //定位未讀數會話
    self.index = 0;
    //接收定位到未讀數會話的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GotoNextCoversation) name:@"GotoNextCoversation" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateForSharedMessageInsertSuccess) name:@"RCDSharedMessageInsertSuccess" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshCell:) name:@"RefreshConversationList" object:nil];
  
    //網絡判斷
    //[self networkStateView];
    
 
}

通知的方法的實現

代碼:

-(void) GotoNextCoversation
{
    NSUInteger i;
    //設置contentInset是爲了滾動到底部的時候,避免conversationListTableView自動回滾。
    self.conversationListTableView.contentInset = UIEdgeInsetsMake(0, 0, self.conversationListTableView.frame.size.height, 0);
    for (i = self.index + 1; i < self.conversationListDataSource.count; i++) {
        RCConversationModel *model = self.conversationListDataSource[i];
        if (model.unreadMessageCount > 0) {
            NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
            self.index = i;
            [self.conversationListTableView scrollToRowAtIndexPath:scrollIndexPath
                                                  atScrollPosition:UITableViewScrollPositionTop animated:YES];
            break;
        }
    }
    //滾動到起始位置
    if (i >= self.conversationListDataSource.count) {
        //    self.conversationListTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        for (i = 0; i < self.conversationListDataSource.count; i++) {
            RCConversationModel *model = self.conversationListDataSource[i];
            if (model.unreadMessageCount > 0) {
                NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
                self.index = i;
                [self.conversationListTableView scrollToRowAtIndexPath:scrollIndexPath
                                                      atScrollPosition:UITableViewScrollPositionTop animated:YES];
                break;
            }
        }
    }
}

- (void)updateForSharedMessageInsertSuccess{
    [self refreshConversationTableViewIfNeeded];
}
-(void)refreshCell:(NSNotification *)notify
{
    [self refreshConversationTableViewIfNeeded];
}

- (void)updateBadgeValueForTabBarItem {
    __weak typeof(self) __weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        int count = [[RCIMClient sharedRCIMClient]
                     getUnreadCount:self.displayConversationTypeArray];
        if (count > 0) {
            NSLog(@"count:%d",count);
            
     
            [__weakSelf.tabBarController.tabBar showBadgeOnItemIndex:1 badgeValue:count];
            
        } else {
        
            [__weakSelf.tabBarController.tabBar hideBadgeOnItemIndex:1];
        }
        
    });
}

headerView的就不說了,這樣會話列表已經能夠顯示了,點擊行單元跳轉聊天界面

代碼:

//點擊會話列表時調用
- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType
         conversationModel:(RCConversationModel *)model
               atIndexPath:(NSIndexPath *)indexPath {
    RCConversationViewController *conversationVC = [[RCConversationViewController alloc]init];
    conversationVC.conversationType = model.conversationType;
    conversationVC.targetId = model.targetId;
    conversationVC.title = model.conversationTitle;

    [self.navigationController pushViewController:conversationVC animated:YES];
}

//設置行高
- (CGFloat)rcConversationListTableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

 

此外:若是修改了我的的頭像和名稱時,要記得刷新融雲的我的信息,一樣圈聊的信息也要刷新,這樣聊天的頭像和暱稱以及圈聊的頭像和名字就可以在修改後馬上見效。

//刷新融雲的我的信息
-(void)refreshRongCloudInfo
{
   //修改以後的我的信息
    RCUserInfo *info = [[RCUserInfo alloc] initWithUserId:[[NSUserDefaults standardUserDefaults] objectForKey:@"ryuid"] name:[[NSUserDefaults standardUserDefaults] objectForKey:@"nickname"] portrait:[[NSUserDefaults standardUserDefaults] objectForKey:@"headimgurl"]];
    
   //傳給融雲的SDK中
    [[RCIM sharedRCIM] refreshUserInfoCache:info withUserId:[[NSUserDefaults standardUserDefaults] objectForKey:@"ryuid"]];
    
}

 

//更新融雲羣聊的信息
-(void)refreshCirclePhotoWithimageUrl:(NSString *)imgUrl
{
    //修改以後的羣聊信息
    RCGroup *info = [[RCGroup alloc] init];
    info.groupId = _dataDict[@"ry_gid"];
    info.groupName = _dataDict[@"gname"];
    info.portraitUri = imgUrl;
    
   //傳遞給融雲的SDK
    [[RCIM sharedRCIM] refreshGroupInfoCache:info withGroupId:info.groupId];
    
}

 

寫的比較匆忙,只是稍做整理,有不足之處,感謝留言,謝謝!

相關文章
相關標籤/搜索