第三方聊天---環(huán)信

環(huán)信 聊天

 框架
    App
    Easy UI    (UI控件)
    SDK        基于核心協(xié)議實(shí)現(xiàn)的完整的 IM 功能,實(shí)現(xiàn)了不同類(lèi)型消息的收發(fā)、會(huì)話管理、群組、好友、聊天室等功能
    SDK_CORE   為核心的消息同步協(xié)議實(shí)現(xiàn),完成與服務(wù)器之間的信息交換
 
 SDK
    EMClient               SDK的入口,主要完成登錄、退出、連接管理等功能,也是獲取其他模塊的入口。
    EMClientManager        管理消息的收發(fā),完成會(huì)話管理等功能
    EMContactManager       負(fù)責(zé)好友的添加刪除,黑名單的管理
    EMGroupManager         負(fù)責(zé)群組的管理,創(chuàng)建、刪除群組,管理群組成員等功能
    EMChatroomManager      負(fù)責(zé)聊天室的管理

配置

1. 蘋(píng)果開(kāi)發(fā)官網(wǎng)創(chuàng)建 2推送證書(shū)(開(kāi)發(fā)證書(shū) 和 線上證書(shū))
2. 環(huán)信開(kāi)發(fā)者中心注冊(cè)應(yīng)用(添加上述2推送證書(shū))(獲取KEY)
pod 'Hyphenate'     包含實(shí)時(shí)語(yǔ)音功能
pod 'EaseUI'        快速集成UI
#import <Hyphenate/Hyphenate.h>
AppDelegate
    
    // 在環(huán)信中注冊(cè)本應(yīng)用
    EMOptions *options=[EMOptions optionsWithAppkey:@"64619039#kachamao"];
    // 證書(shū)
#if DEBUG
    [options setApnsCertName:@"s_dev"];
#else
    [options setApnsCertName:@"s_product"];
#endif
    [[EMClient sharedClient]initializeSDKWithOptions:options];

 
// APP進(jìn)入后臺(tái)
- (void)applicationDidEnterBackground:(UIApplication *)application{
    // 環(huán)信進(jìn)入后臺(tái)
    [[EMClient sharedClient] applicationDidEnterBackground:application];
}


// APP將要從后臺(tái)返回前臺(tái)
- (void)applicationWillEnterForeground:(UIApplication *)application{
    // 環(huán)信即將進(jìn)入前臺(tái)
    [[EMClient sharedClient] applicationWillEnterForeground:application];
}

注冊(cè)登錄

注冊(cè)
EMError *error = [[EMClient sharedClient] registerWithUsername:@"唯一表示用戶(hù)" password:@"111111"];
if (error==nil) {
    NSLog(@"注冊(cè)成功");
}


登陸
[[EMClient sharedClient] loginWithUsername:@"8001"
                                  password:@"111111"
                                completion:^(NSString *aUsername, EMError *aError) {
                                    if (!aError) {
                                        NSLog(@"登錄成功");
                                    } else {
                                        NSLog(@"登錄失敗");
                                    }
                                }];



// 以下情況會(huì)導(dǎo)致自動(dòng)登錄失敗
  1.用戶(hù)調(diào)用了 SDK 的登出動(dòng)作;
  2.用戶(hù)在別的設(shè)備上更改了密碼,導(dǎo)致此設(shè)備上自動(dòng)登錄失?。?  3.用戶(hù)的賬號(hào)被從服務(wù)器端刪除;
  4.用戶(hù)從另一個(gè)設(shè)備登錄,把當(dāng)前設(shè)備上登錄的用戶(hù)踢出。
自動(dòng)登錄
BOOL isAutoLogin = [EMClient sharedClient].options.isAutoLogin;
if (!isAutoLogin) {
    EMError *error = [[EMClient sharedClient] loginWithUsername:@"8001" password:@"111111"];
    if (!error)
    {
        [[EMClient sharedClient].options setIsAutoLogin:YES];
    }
}
// 自動(dòng)登錄后調(diào)用
- (void)autoLoginDidCompleteWithError:(EMError *)error{}
// 重連時(shí)回調(diào)
- (void)connectionStateDidChange:(EMConnectionState)aConnectionState{}



退出登錄
  -》主動(dòng)退出登錄:調(diào)用 SDK 的退出接口;
  -》被動(dòng)退出登錄:1. 正在登錄的賬號(hào)在另一臺(tái)設(shè)備上登錄;2. 正在登錄的賬號(hào)被從服務(wù)器端刪除。

// 主動(dòng)退出登錄
EMError *error = [[EMClient sharedClient] logout:YES];
if (!error) {
    NSLog(@"退出成功");
}
// 當(dāng)用戶(hù)從另一個(gè)設(shè)備登錄此賬號(hào)時(shí)調(diào)用
- (void)userAccountDidLoginFromOtherDevice{}
// 當(dāng)用戶(hù)的賬號(hào)被從服務(wù)器端刪除時(shí)調(diào)用
- (void)userAccountDidRemoveFromServer{}

好友

// 從服務(wù)器獲取所有的好友
[[EMClient sharedClient].contactManager getContactsFromServerWithCompletion:^(NSArray *aList, EMError *aError) {
    if (!aError) {
        NSLog(@"獲取成功");
    }
}];
// 從數(shù)據(jù)庫(kù)獲取所有的好友
NSArray *userlist = [[EMClient sharedClient].contactManager getContacts];
// 發(fā)送 添加好友 申請(qǐng)
[[EMClient sharedClient].contactManager addContact:@"8001"
                                           message:@"我想加您為好友"
                                        completion:^(NSString *aUsername, EMError *aError) {
                                            if (!aError) {
                                                NSLog(@"邀請(qǐng)發(fā)送成功");
                                            }
                                        }];

// 同意好友申請(qǐng)
[[EMClient sharedClient].contactManager approveFriendRequestFromUser:@"8001"
                                                          completion:^(NSString *aUsername, EMError *aError) {
                                                              if (!aError) {
                                                                  NSLog(@"同意好友成功");
                                                              }
                                                          }];

// 拒絕好友申請(qǐng)
[[EMClient sharedClient].contactManager declineFriendRequestFromUser:@"8001"
                                                          completion:^(NSString *aUsername, EMError *aError) {
                                                              if (!aError) {
                                                                  NSLog(@"拒絕好友成功");
                                                              }
                                                          }];

// 刪除好友
[[EMClient sharedClient].contactManager deleteContact:@"8001"
                                 isDeleteConversation: YES
                                           completion:^(NSString *aUsername, EMError *aError) {
                                               if (!aError) {
                                                   NSLog(@"刪除成功");
                                               }
                                           }];
    // 注冊(cè)好友dele <EMContactManagerDelegate>
    [[EMClient sharedClient].contactManager addDelegate:self delegateQueue:nil];
    // 移除dele
    [[EMClient sharedClient].contactManager removeDelegate:self];
    
    // 對(duì)方同意加好友請(qǐng)求后回調(diào)
    - (void)friendRequestDidApproveByUser:(NSString *)aUsername{}
    // 對(duì)方拒絕加好友請(qǐng)求后回調(diào)
    - (void)friendRequestDidDeclineByUser:(NSString *)aUsername{}
    // 對(duì)方刪除我,雙方都回調(diào)
    - (void)friendshipDidRemoveByUser:(NSString *)aUsername{}
    // 對(duì)方同意好友請(qǐng)求后,雙方回調(diào)
    - (void)friendshipDidAddByUser:(NSString *)aUsername{}
    // 對(duì)方發(fā)送好友請(qǐng)求后回調(diào)
    - (void)friendRequestDidReceiveFromUser:(NSString *)aUsername message:(NSString *)aMessage{}

    // 獲取好友黑名單
    EMError *error = nil;
    NSArray *blackList = [[EMClient sharedClient].contactManager getBlackListFromServerWithError:&error];
    if (!error) {
        NSLog(@"獲取成功 -- %@",blackList);
    }
    // 從數(shù)據(jù)庫(kù)獲取黑名單列表
    NSArray *blockList = [[EMClient sharedClient].contactManager getBlackList];
    
    
    // 加入黑名單
    EMError *error = [[EMClient sharedClient].contactManager addUserToBlackList:@"6001" relationshipBoth:YES];
    if (!error) {
        NSLog(@"發(fā)送成功");
    }
    
    // 移除黑名單
    EMError *error = [[EMClient sharedClient].contactManager removeUserFromBlackList:@"6001"];
    if (!error) {
        NSLog(@"發(fā)送成功");
    }

會(huì)話

獲取所有會(huì)話(內(nèi)存中有則從內(nèi)存中取,沒(méi)有則從db中取)
 NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];

獲取或創(chuàng)建會(huì)話
 EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:@"8001" type:EMConversationTypeChat createIfNotExist:YES];
     EMConversationTypeChat            單聊會(huì)話
     EMConversationTypeGroupChat       群聊會(huì)話
     EMConversationTypeChatRoom        聊天室會(huì)話
 
刪除會(huì)話
 [[EMClient sharedClient].chatManager deleteConversation:@"8001" isDeleteMessages:YES completion:^(NSString *aConversationId, EMError *aError){
 //code
 }];
 
根據(jù) conversationId 批量刪除會(huì)話
 EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:@"8001" type:EMConversationTypeChat createIfNotExist:NO];
 [[EMClient sharedClient].chatManager deleteConversations:@[conversation] isDeleteMessages:YES completion:^(EMError *aError){
 //code
 }];

獲取會(huì)話未讀消息數(shù)
 [EMConversation unreadMessagesCount];


獲取會(huì)話中的消息
    // 從數(shù)據(jù)庫(kù)獲取時(shí)間段內(nèi)的消息(時(shí)間單位:毫秒),最大數(shù)量10
    [conversion loadMessagesFrom:1000 to:1000 count:10 completion:^(NSArray *aMessages, EMError *aError) {
        // 獲取完畢后回調(diào)
    }];
    //  從數(shù)據(jù)庫(kù)獲取指定id的消息
    [conversion loadMessageWithId:@"messageId" error:nil];
    // 從數(shù)據(jù)庫(kù)獲取從指定id的消息(不包含)后開(kāi)始10條消息
    [conversion loadMessagesStartFromId:@"messageId" count:10 searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {
    }];
    // 從數(shù)據(jù)庫(kù)獲取從指定時(shí)間(毫秒)指定發(fā)送人,從上到下10條消息
    [conversion loadMessagesWithType:EMMessageBodyTypeText timestamp:1000 count:10 fromUser:@"" searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {
    }];
    // 從數(shù)據(jù)庫(kù)獲取從指定時(shí)間(毫秒)指定發(fā)送人包含關(guān)鍵字,從上到下10條消息
    [conversion loadMessagesWithKeyword:@"keyWord" timestamp:1000 count:10 fromUser:@"" searchDirection:EMMessageSearchDirectionUp completion:^(NSArray *aMessages, EMError *aError) {
    }];

消息

1.消息體
文本消息
 EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"要發(fā)送的消息"];
圖片消息
 EMImageMessageBody *body = [[EMImageMessageBody alloc] initWithData:data displayName:@"image.png"];
位置消息
 EMLocationMessageBody *body = [[EMLocationMessageBody alloc] initWithLatitude:39 longitude:116 address:@"地址"];
語(yǔ)音消息
 EMVoiceMessageBody *body = [[EMVoiceMessageBody alloc] initWithLocalPath:@"audioPath" displayName:@"audio"];
 body.duration = duration;
視頻消息
 EMVideoMessageBody *body = [[EMVideoMessageBody alloc] initWithLocalPath:@"videoPath" displayName:@"video.mp4"];
文件消息
 EMFileMessageBody *body = [[EMFileMessageBody alloc] initWithLocalPath:@"filePath" displayName:@"file"];
透?jìng)飨? EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:action];
 2.消息
 // 消息
 NSString *from = [[EMClient sharedClient] currentUsername];
 EMMessage *message = [[EMMessage alloc] initWithConversationID:@"6001" from:from to:@"6001" body:body ext:messageExt];
 message.chatType = EMChatTypeChat;         // 單聊,EMChatTypeGroupChat群聊 EMChatTypeChatRoom聊天室
 message.ext = @{@"key":@"value"};          // 擴(kuò)展消息
 
 3.插入消息
 [[EMClient sharedClient].chatManager importMessages:@[message] completion:^(EMError *aError) {
 //code
 }];

 3.發(fā)送消息(異步)
 [[EMClient sharedClient].chatManager sendMessage:[EMMessage new] progress:^(int progress) {
 } completion:^(EMMessage *message, EMError *error) {
 }];
 

 // 更新消息到 DB
 [[EMClient sharedClient].chatManager updateMessage:aMessage];
 // 添加dele   <EMChatManagerDelegate>
 [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
 // 移除dele
 [[EMClient sharedClient].chatManager removeDelegate:self];


// 收到消息(非透?jìng)鳎┖蠡卣{(diào)
- (void)messagesDidReceive:(NSArray *)aMessages{
    
    //
    for (EMMessage *message in aMessages) {
        // 消息中的擴(kuò)展屬性
        NSDictionary *ext = message.ext;
    
        
        EMMessageBody *msgBody = message.body;
        switch (msgBody.type) {
            case EMMessageBodyTypeText:{
                // 收到的文字消息
                EMTextMessageBody *textBody = (EMTextMessageBody *)msgBody;
                NSString *txt = textBody.text;
                NSLog(@"收到的文字是 txt -- %@",txt);
            }
                break;
            case EMMessageBodyTypeImage:{
                // 得到一個(gè)圖片消息body
                EMImageMessageBody *body = ((EMImageMessageBody *)msgBody);
                NSLog(@"大圖remote路徑 -- %@"   ,body.remotePath);
                NSLog(@"大圖local路徑 -- %@"    ,body.localPath); // // 需要使用sdk提供的下載方法后才會(huì)存在
                NSLog(@"大圖的secret -- %@"    ,body.secretKey);
                NSLog(@"大圖的W -- %f ,大圖的H -- %f",body.size.width,body.size.height);
                NSLog(@"大圖的下載狀態(tài) -- %lu",body.downloadStatus);
                
                
                // 縮略圖sdk會(huì)自動(dòng)下載
                NSLog(@"小圖remote路徑 -- %@"   ,body.thumbnailRemotePath);
                NSLog(@"小圖local路徑 -- %@"    ,body.thumbnailLocalPath);
                NSLog(@"小圖的secret -- %@"    ,body.thumbnailSecretKey);
                NSLog(@"小圖的W -- %f ,大圖的H -- %f",body.thumbnailSize.width,body.thumbnailSize.height);
                NSLog(@"小圖的下載狀態(tài) -- %lu",body.thumbnailDownloadStatus);
            }
                break;
            case EMMessageBodyTypeLocation:{
                
                EMLocationMessageBody *body = (EMLocationMessageBody *)msgBody;
                NSLog(@"緯度-- %f",body.latitude);
                NSLog(@"經(jīng)度-- %f",body.longitude);
                NSLog(@"地址-- %@",body.address);
            }
                break;
            case EMMessageBodyTypeVoice:{
                
                // 音頻sdk會(huì)自動(dòng)下載
                EMVoiceMessageBody *body = (EMVoiceMessageBody *)msgBody;
                NSLog(@"音頻remote路徑 -- %@"      ,body.remotePath);
                NSLog(@"音頻local路徑 -- %@"       ,body.localPath); // 需要使用sdk提供的下載方法后才會(huì)存在(音頻會(huì)自動(dòng)調(diào)用)
                NSLog(@"音頻的secret -- %@"        ,body.secretKey);
                NSLog(@"音頻文件大小 -- %lld"       ,body.fileLength);
                NSLog(@"音頻文件的下載狀態(tài) -- %lu"   ,body.downloadStatus);
                NSLog(@"音頻的時(shí)間長(zhǎng)度 -- %lu"      ,body.duration);
            }
                break;
            case EMMessageBodyTypeVideo:{
                
                EMVideoMessageBody *body = (EMVideoMessageBody *)msgBody;
                
                NSLog(@"視頻remote路徑 -- %@"      ,body.remotePath);
                NSLog(@"視頻local路徑 -- %@"       ,body.localPath); // 需要使用sdk提供的下載方法后才會(huì)存在
                NSLog(@"視頻的secret -- %@"        ,body.secretKey);
                NSLog(@"視頻文件大小 -- %lld"       ,body.fileLength);
                NSLog(@"視頻文件的下載狀態(tài) -- %lu"   ,body.downloadStatus);
                NSLog(@"視頻的時(shí)間長(zhǎng)度 -- %lu"      ,body.duration);
                NSLog(@"視頻的W -- %f ,視頻的H -- %f", body.thumbnailSize.width, body.thumbnailSize.height);
                
                // 縮略圖sdk會(huì)自動(dòng)下載
                NSLog(@"縮略圖的remote路徑 -- %@"     ,body.thumbnailRemotePath);
                NSLog(@"縮略圖的local路徑 -- %@"      ,body.thumbnailLocalPath);
                NSLog(@"縮略圖的secret -- %@"        ,body.thumbnailSecretKey);
                NSLog(@"縮略圖的下載狀態(tài) -- %lu"      ,body.thumbnailDownloadStatus);
            }
                break;
            case EMMessageBodyTypeFile:{
                
                EMFileMessageBody *body = (EMFileMessageBody *)msgBody;
                NSLog(@"文件remote路徑 -- %@"      ,body.remotePath);
                NSLog(@"文件local路徑 -- %@"       ,body.localPath); // 需要使用sdk提供的下載方法后才會(huì)存在
                NSLog(@"文件的secret -- %@"        ,body.secretKey);
                NSLog(@"文件文件大小 -- %lld"       ,body.fileLength);
                NSLog(@"文件文件的下載狀態(tài) -- %lu"   ,body.downloadStatus);
            }
                break;
                
            default:
                break;
        }
    }
}
// 收到透?jìng)?cmd)在線消息后回調(diào)
- (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages{
    for (EMMessage *message in aCmdMessages) {
        
        // cmd消息中的擴(kuò)展屬性
        NSDictionary *ext = message.ext;
        
        
        EMCmdMessageBody *body = (EMCmdMessageBody *)message.body;
        NSLog(@"收到的action是 -- %@",body.action);
    }
}


// 會(huì)話列表變動(dòng)后調(diào)用
- (void)conversationListDidUpdate:(NSArray *)aConversationList{}
// 收到消息后調(diào)用
- (void)messagesDidReceive:(NSArray *)aMessages{}
// 收到cmd透?jìng)飨⒑笳{(diào)用
- (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages{}
// 消息已讀后回調(diào)
- (void)messagesDidRead:(NSArray *)aMessages{}
// 消息送達(dá)后回調(diào)
- (void)messagesDidDeliver:(NSArray *)aMessages{}
// 消息撤回后回調(diào)
- (void)messagesDidRecall:(NSArray *)aMessages{}
// 消息狀態(tài)改變時(shí)調(diào)用
- (void)messageStatusDidChange:(EMMessage *)aMessage error:(EMError *)aError{}
// 消息附件狀態(tài)改變時(shí)調(diào)用
- (void)messageAttachmentStatusDidChange:(EMMessage *)aMessage error:(EMError *)aError{}

群組

群組類(lèi)型(4種)
    EMGroupStylePrivateOnlyOwnerInvite 私有群組,創(chuàng)建完成后,只允許 Owner 邀請(qǐng)用戶(hù)加入
    EMGroupStylePrivateMemberCanInvite 私有群組,創(chuàng)建完成后,只允許 Owner 和群成員邀請(qǐng)用戶(hù)加入
    EMGroupStylePublicJoinNeedApproval 公開(kāi)群組,創(chuàng)建完成后,只允許 Owner 邀請(qǐng)用戶(hù)加入; 非群成員用戶(hù)需發(fā)送入群申請(qǐng),Owner 同意后才能入組
    EMGroupStylePublicOpenJoin         公開(kāi)群組,創(chuàng)建完成后,允許非群組成員加入,不需要管理員同意
創(chuàng)建群組
    EMError *error = nil;
    EMGroupOptions *setting = [[EMGroupOptions alloc] init];
    setting.maxUsersCount = 500;
    setting.style = EMGroupStylePublicOpenJoin;// 創(chuàng)建不同類(lèi)型的群組,這里需要才傳入不同的類(lèi)型
    EMGroup *group = [[EMClient sharedClient].groupManager createGroupWithSubject:@"群組名稱(chēng)" description:@"群組描述" invitees:@[@"6001",@"6002"] message:@"邀請(qǐng)您加入群組" setting:setting error:&error];
    if(!error){
        NSLog(@"創(chuàng)建成功 -- %@",group);
    }

獲取群詳情
    // 獲取群詳情
    EMGroup *group=[[EMClient sharedClient].groupManager getGroupSpecificationFromServerWithId:@"groupId" error:nil];
    // 獲取群詳情
    [[EMClient sharedClient].groupManager getGroupSpecificationFromServerWithId:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    
    // 申請(qǐng)加入群組
    EMError *error = nil;
    [[EMClient sharedClient].groupManager applyJoinPublicGroup:@"groupId" message:@"" error:nil];
    // 管理員 加人進(jìn)群
    EMError *error = nil;
    [[EMClient sharedClient].groupManager addOccupants:@[@"user1"] toGroup:@"groupId" welcomeMessage:@"message" error:&error];
    // 管理員 同意進(jìn)群申請(qǐng)
    EMError *error = [[EMClient sharedClient].groupManager acceptJoinApplication:@"groupId" applicant:@"user1"];
    // 管理員 拒絕加群申請(qǐng)
    EMError *error = [[EMClient sharedClient].groupManager declineJoinApplication:@"groupId" groupname:@"subject" applicant:@"user1" reason:@"拒絕的原因"];
    
    // 加入公開(kāi)群
    MError *error = nil;
    [[EMClient sharedClient].groupManager joinPublicGroup:@"1410329312753" error:&error];
    
    // 主動(dòng)退群
    EMError *error = nil;
    [[EMClient sharedClient].groupManager leaveGroup:@"1410329312753" error:&error];
    
    // 解散群組
    EMError *error = nil;
    [[EMClient sharedClient].groupManager destroyGroup:@"groupId" error:&error];
    if (!error) {
        NSLog(@"解散成功");
    }
    
    // 修改群名稱(chēng)
    EMError *error = nil;
    [[EMClient sharedClient].groupManager changeGroupSubject:@"要修改的名稱(chēng)" forGroup:@"1410329312753" error:&error];
    if (!error) {
        NSLog(@"修改成功");
    }
    // 修改群描述
    EMError *error = nil;
    EMGroup* group = [[EMClient sharedClient].groupManager changeDescription:@"修改的群描述" forGroup:@"1410329312753" error:&error];
    if (!error) {
        NSLog(@"修改成功");
    }
    
    // 獲取群成員列表
    EMError *error = nil;
    EMCursorResult* result = [[EMClient sharedClient].groupManager getGroupMemberListFromServerWithId:@"groupId" cursor:@"cursor" pageSize:50 error:&error];
    if (!error) {
        NSLog(@"獲取成功");
        // result.list: 返回的成員列表,內(nèi)部的值是成員的環(huán)信id。
        // result.cursor: 返回的cursor,如果要取下一頁(yè)的列表,需要將這個(gè)cursor當(dāng)參數(shù)傳入到獲取群組成員列表中。
    }
    // 異步 
    [[EMClient sharedClient].groupManager getGroupMemberListFromServerWithId:@"" cursor:@"" pageSize:50 completion:^(EMCursorResult *aResult, EMError *aError) {
    }];
    
    // 獲取群黑名單列表
    EMError *error = nil;
    EMGroup* group = [[EMClient sharedClient].groupManager getGroupBlacklistFromServerWithId:@"groupId" pageNumber:1 pageSize:50 error:&error];
    if (!error) {
        NSLog(@"獲取成功");
    }
    // 異步
    [[EMClient sharedClient].groupManager getGroupBlacklistFromServerWithId:@"" pageNumber:@1 pageSize:@50 completion:^(NSArray *aList, EMError *aError) {
    }];

    // 獲取被禁言列表
    EMError *error = nil;
    EMGroup* group = [[EMClient sharedClient].groupManager getGroupMuteListFromServerWithId:@"groupId" pageNumber:1 pageSize:50 error:&error];
    if (!error) {
        NSLog(@"獲取成功");
    }
    // 異步
    [[EMClient sharedClient].groupManager getGroupMuteListFromServerWithId:@"" pageNumber:1 pageSize:50 completion:^(NSArray *aList, EMError *aError) {
}];
    
    // 獲取群公告
    [[EMClient sharedClient].groupManager getGroupAnnouncementWithId:@"groupId"
                                                          completion:^(NSString *aAnnouncement, EMError *aError) {
                                                              if (!aError) {
                                                                  NSLog(@"獲取成功");
                                                              }
                                                          }];
    // 異步
    [[EMClient sharedClient].groupManager updateGroupAnnouncementWithId:@"" announcement:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    
    // 修改群公告
    [[EMClient sharedClient].groupManager updateGroupAnnouncementWithId:@"groupid"
                                                           announcement:@"群公告"
                                                             completion:^(EMGroup *aGroup, EMError *aError) {
                                                                 if (!aError) {
                                                                     NSLog(@"修改成功");
                                                                 }
                                                             }];
    
    
    // 獲取群共享文件列表
    // 同步
    NSArray *arr=[[EMClient sharedClient].groupManager getGroupFileListWithId:@"" pageNumber:1 pageSize:10 error:nil];
    // 異步
    [[EMClient sharedClient].groupManager getGroupFileListWithId:@"groupId"
                                                      pageNumber:1
                                                        pageSize:10
                                                      completion:^(NSArray *aList, EMError *aError) {
                                                          if (!aError) {
                                                              NSLog(@"獲取成功");
                                                          }
                                                      }];
    
    // 上傳群文件
    [[EMClient sharedClient].groupManager uploadGroupSharedFileWithId:@"groupId"
                                                             filePath:@"filePath"
                                                             progress:^(int progress){
                                                             } completion:^(EMGroupSharedFile *aSharedFile, EMError *aError) {
                                                                 if (!aError) {
                                                                     NSLog(@"上傳成功");
                                                                 }
                                                             }];
    // 下載群文件
    [[EMClient sharedClient].groupManager downloadGroupSharedFileWithId:@"groupId"
                                                               filePath:@"filePath"
                                                           sharedFileId:@"fileId"
                                                               progress:^(int progress) {
                                                               } completion:^(EMGroup *aGroup, EMError *aError) {
                                                                   if (!aError) {
                                                                       NSLog(@"下載成功");
                                                                   }
                                                               }];
    // 刪除共享文件 同步
    EMError *error = nil;
    [[EMClient sharedClient].groupManager removeGroupSharedFileWithId:@"groupId" sharedFileId:@"fileId" error:&error];
    if (!error) {
        NSLog(@"刪除成功");
    }
     // 異步
    [[EMClient sharedClient].groupManager removeGroupSharedFileWithId:@"" sharedFileId:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    
    // 修改群擴(kuò)展信息(同步/異步)
    [[EMClient sharedClient].groupManager updateGroupExtWithId:@"" ext:@"" error:nil];
    [[EMClient sharedClient].groupManager updateGroupExtWithId:@"groupId"
                                                           ext:@"ext"
                                                    completion:^(EMGroup *aGroup, EMError *aError) {
                                                        if (!aError) {
                                                            NSLog(@"修改成功");
                                                        }
                                                    }];
    

    // 改變?nèi)褐鳎ū仨毷侨褐鳎?    EMError *error = nil;
    [[EMClient sharedClient].groupManager updateGroupOwner:@"groupId" newOwner:@"newOwner" error:&error];
    // 改變?nèi)褐鳎ó惒剑?    [[EMClient sharedClient].groupManager updateGroupOwner:@"" newOwner:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 添加群管理員
    EMError *error = nil;
    [[EMClient sharedClient].groupManager addAdmin:@"adminName" toGroup:@"groupId" error:&error];
    [[EMClient sharedClient].groupManager addAdmin:@"" toGroup:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 移除群管理員
    EMError *error = nil;
    [[EMClient sharedClient].groupManager removeAdmin:@"adminName" fromGroup:@"groupId" error:&error];
    [[EMClient sharedClient].groupManager removeAdmin:@"" fromGroup:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 移除群成員
    EMError *error = nil;
    [[EMClient sharedClient].groupManager removeOccupants:@[@"user1"] fromGroup:@"1410329312753" error:&error];
    [[EMClient sharedClient].groupManager removeMembers:@[] fromGroup:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 禁言群成員
    EMError *error = nil;
    [[EMClient sharedClient].groupManager muteMembers:@[userName] muteMilliseconds:-1 fromGroup:@"groupId" error:&error];
    [[EMClient sharedClient].groupManager muteMembers:@"" muteMilliseconds:30 fromGroup:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 解禁言群成員
    EMError *error = nil;
    [[EMClient sharedClient].groupManager unmuteMembers:@[userName] fromGroup:@"groupId" error:&error];
    [[EMClient sharedClient].groupManager unmuteMembers:@[] fromGroup:@"" completion:^(EMGroup *aGroup, EMError *aError) {
    }];
    // 加入群黑名單
    EMError *error = nil;
    EMGroup *group = [[EMClient sharedClient].groupManager blockOccupants:@[@"user1"] fromGroup:@"1410329312753" error:&error];
    // 移除群黑名單
    EMError *error = nil;
    EMGroup *group = [[EMClient sharedClient].groupManager unblockOccupants:@[@"user1"] forGroup:@"1410329312753" error:&error];
    
    
    // 屏蔽/取消屏蔽 群消息
    [[EMClient sharedClient].groupManager blockGroup:@"groupId" error:nil];
    [[EMClient sharedClient].groupManager unblockGroup:@"groupId" error:nil];
    
    
    // 內(nèi)存中獲取所有群組,第一次從數(shù)據(jù)庫(kù)加載
    NSArray *groupList = [[EMClient sharedClient].groupManager getJoinedGroups];
    // 獲取和登錄者相關(guān)的群組
    EMError *error = nil;
    NSArray *myGroups = [[EMClient sharedClient].groupManager getJoinedGroupsFromServerWithPage:1 pageSize:50 error:&error];
    if (!error) {
        NSLog(@"獲取成功 -- %@",myGroups);
    }
    // 獲取公開(kāi)群組
    EMError *error = nil;
    EMCursorResult *result = [[EMClient sharedClient].groupManager getPublicGroupsFromServerWithCursor:nil pageSize:50 error:&error];
    if (!error) {
        NSLog(@"獲取成功 -- %@",result);
    }
    // 群組dele <EMGroupManagerDelegate>
    [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
    // 移除群組dele
    [[EMClient sharedClient].groupManager removeDelegate:self];

    // 對(duì)方邀請(qǐng)我加入某群時(shí)調(diào)用
    - (void)groupInvitationDidReceive:(NSString *)aGroupId inviter:(NSString *)aInviter message:(NSString *)aMessage{}
    // 對(duì)方同意我的加群邀請(qǐng)時(shí)調(diào)用
    - (void)groupInvitationDidAccept:(EMGroup *)aGroup invitee:(NSString *)aInvitee{}
    // 對(duì)方拒絕我的加群邀請(qǐng)時(shí)調(diào)用
    - (void)groupInvitationDidDecline:(EMGroup *)aGroup invitee:(NSString *)aInvitee reason:(NSString *)aReason{}
    // 自動(dòng)加入群后回調(diào)(對(duì)方邀請(qǐng))(EMOptions的isAutoAcceptGroupInvitation為YES)
    - (void)didJoinGroup:(EMGroup *)aGroup inviter:(NSString *)aInviter message:(NSString *)aMessage{}
    // 離開(kāi)群組后回調(diào)
    - (void)didLeaveGroup:(EMGroup *)aGroup reason:(EMGroupLeaveReason)aReason{}
    // 收到入群請(qǐng)求后回調(diào)(群的類(lèi)型是EMGroupStylePublicJoinNeedApproval)
    - (void)joinGroupRequestDidReceive:(EMGroup *)aGroup user:(NSString *)aUsername reason:(NSString *)aReason{}
    // 申請(qǐng)入群被拒后回調(diào)(群的類(lèi)型是EMGroupStylePublicJoinNeedApproval)
    - (void)joinGroupRequestDidDecline:(NSString *)aGroupId reason:(NSString *)aReason{}
    // 申請(qǐng)入群被同意后回調(diào)(群的類(lèi)型是EMGroupStylePublicJoinNeedApproval)
    - (void)joinGroupRequestDidApprove:(EMGroup *)aGroup{}
    // 群組列表更新后回調(diào)
    - (void)groupListDidUpdate:(NSArray *)aGroupList{}
    // 有成員被加入禁言列表后調(diào)用
    - (void)groupMuteListDidUpdate:(EMGroup *)aGroup addedMutedMembers:(NSArray *)aMutedMembers muteExpire:(NSInteger)aMuteExpire{}
    // 有成員被移除禁言列表后調(diào)用
    - (void)groupMuteListDidUpdate:(EMGroup *)aGroup removedMutedMembers:(NSArray *)aMutedMembers{}
    // 有成員被加入管理員列表后調(diào)用
    - (void)groupAdminListDidUpdate:(EMGroup *)aGroup addedAdmin:(NSString *)aAdmin{}
    // 有成員被移除管理員列表后調(diào)用
    - (void)groupAdminListDidUpdate:(EMGroup *)aGroup removedAdmin:(NSString *)aAdmin{}
    // 群組創(chuàng)建者更新后回調(diào)
    - (void)groupOwnerDidUpdate:(EMGroup *)aGroup newOwner:(NSString *)aNewOwner oldOwner:(NSString *)aOldOwner{}
    // 有用戶(hù)加入群組后回調(diào)
    - (void)userDidJoinGroup:(EMGroup *)aGroup user:(NSString *)aUsername{}
    // 有用戶(hù)離開(kāi)群組后調(diào)用
    - (void)userDidLeaveGroup:(EMGroup *)aGroup user:(NSString *)aUsername{}
    // 群公告更新后調(diào)用
    - (void)groupAnnouncementDidUpdate:(EMGroup *)aGroup announcement:(NSString *)aAnnouncement{}
    // 有用戶(hù)上傳文件后調(diào)用
    - (void)groupFileListDidUpdate:(EMGroup *)aGroup addedSharedFile:(EMGroupSharedFile *)aSharedFile{}
    // 有用戶(hù)刪除群共享文件
    - (void)groupFileListDidUpdate:(EMGroup *)aGroup removedSharedFile:(NSString *)aFileId{}

群主
// 作為群主 收到入群申請(qǐng)時(shí)調(diào)用
- (void)didReceiveJoinGroupApplication:(EMGroup *)aGroup applicant:(NSString *)aApplicant reason:(NSString *)aReason{}

聊天頁(yè)面

進(jìn)入系統(tǒng)單聊頁(yè)面
 EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"8001" conversationType:EMConversationTypeChat];

進(jìn)入系統(tǒng)群聊頁(yè)面
 EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"groupId" conversationType:EMConversationTypeGroupChat];
    // 下載消息中的附件
    [[EMClient sharedClient].chatManager downloadMessageThumbnail:message progress:^(int progress) {
    } completion:^(EMMessage *message, EMError *error) {
    }];
    // 下載消息中的原始附件
    [[EMClient sharedClient].chatManager downloadMessageAttachment:message progress:^(int progress) {
    } completion:^(EMMessage *message, EMError *error) {
    }];
    
    // 發(fā)送已讀回執(zhí)(需要開(kāi)發(fā)者手動(dòng)調(diào)用)
    [[EMClient sharedClient].chatManager sendMessageReadAck:message completion:^(EMMessage *aMessage, EMError *aError) {
        if(!aError){
            NSLog(@"send success");
        }
    }];
    
    // 獲取消息漫游
    [[EMClient sharedClient].chatManager fetchHistoryMessagesFromServer:@"要獲取漫游消息的Conversation id" conversationType:EMConversationTypeChat startMessageId:@"參考起始消息的ID" pageSize:10 error:nil];
    // 獲取消息漫游(異步)
    [[EMClient sharedClient].chatManager asyncFetchHistoryMessagesFromServer:@"" conversationType:EMConversationTypeChat startMessageId:@"" pageSize:10 complation:^(EMCursorResult *aResult, EMError *aError) {
    }];
    // 撤回消息
    [[EMClient sharedClient].chatManager recallMessage:message completion:^(EMMessage *aMessage, EMError *aError) {
    }];

聊天室

   // 獲取聊天室
    EMError *error = nil;
    NSArray *list = [[EMClient sharedClient].roomManager getChatroomsFromServerWithPage:0 pageSize:50 error:&error];
    [[EMClient sharedClient].roomManager getChatroomsFromServerWithPage:0 pageSize:10 completion:^(EMPageResult *aResult, EMError *aError) {
    }];
    // 加入聊天室
    EMError *error = nil;
    EMChatroom *chatroom = [[EMClient sharedClient].roomManager joinChatroom:@"chatroomId" error:&error];
    [[EMClient sharedClient].roomManager joinChatroom:@"" completion:^(EMChatroom *aChatroom, EMError *aError) {
    }];
    // 移除聊天室
    EMError *error = nil;
    [[EMClient sharedClient].roomManager leaveChatroom:@"chatroomId" error:&error];
    [[EMClient sharedClient].roomManager leaveChatroom:@"" completion:^(EMError *aError) {
}];
    // 獲取聊天室詳情
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager getChatroomSpecificationFromServerWithId:@"roomId"error:&error];
    [[EMClient sharedClient].roomManager getChatroomSpecificationFromServerWithId:@"" completion:^(EMChatroom *aChatroom, EMError *aError) {
    }];
    // 獲取聊天室成員列表
    EMError *error = nil;
    EMCursorResult *result = [[EMClient sharedClient].roomManager getChatroomMemberListFromServerWithId:@"roomId" cursor:@"cursor" pageSize:50 error:&error];
    [[EMClient sharedClient].roomManager getChatroomMemberListFromServerWithId:@"" cursor:@"" pageSize:10 completion:^(EMCursorResult *aResult, EMError *aError) {
 }];
    // 獲取聊天室黑名單
    EMError *error = nil;
    NSArray *list = [[EMClient sharedClient].roomManager getChatroomBlacklistFromServerWithId:@"roomId" pageNumber:1 pageSize:50 error:&error];
    [[EMClient sharedClient].roomManager getChatroomBlacklistFromServerWithId:@"" pageNumber:0 pageSize:10 completion:^(NSArray *aList, EMError *aError) {
    }];
    // 獲取聊天室禁言列表
    EMError *error = nil;
    NSArray *list = [[EMClient sharedClient].roomManager getChatroomMuteListFromServerWithId:@"roomId" pageNumber:1 pageSize:50 error:&error];
    [[EMClient sharedClient].roomManager getChatroomMuteListFromServerWithId:@"" pageNumber:0 pageSize:10 completion:^(NSArray *aList, EMError *aError) {
    }];
    // 更新聊天室名稱(chēng)
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager updateSubject:@"newSubject" forChatroom:@"roomId" error:&error];
    [[EMClient sharedClient].roomManager updateSubject:@"" forChatroom:@"" completion:^(EMChatroom *aChatroom, EMError *aError) {
    }];
    // 更新聊天室說(shuō)明
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager updateDescription:@"newDes" forChatroom:@"roomId" error:&error];
    [[EMClient sharedClient].roomManager getChatroomAnnouncementWithId:@"" completion:^(NSString *aAnnouncement, EMError *aError) {
    }];
    // 獲取聊天室公告
    NSString *content=[[EMClient sharedClient].roomManager getChatroomAnnouncementWithId:@"" error:nil];
    [[EMClient sharedClient].roomManager getChatroomAnnouncementWithId:@"chatroomId"
                                                            completion:^(NSString *aAnnouncement, EMError *aError) {
                                                                if (!aError) {
                                                                    NSLog(@"獲取成功");
                                                                }
                                                            }];
    // 更新聊天室公告
    EMChatroom *room=[[EMClient sharedClient].roomManager updateChatroomAnnouncementWithId:@"" announcement:@"" error:nil];
    [[EMClient sharedClient].roomManager updateChatroomAnnouncementWithId:@"chatroomId"
                                                             announcement:@"announcement"
                                                               completion:^(EMChatroom *aChatroom, EMError *aError) {
                                                                   if (!aError) {
                                                                       NSLog(@"修改成功");
                                                                   }
                                                               }];
    
    // 以下相關(guān)方法都有同步異步執(zhí)行,就省略了

    // 將某成員移除聊天室
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager removeMembers:@[@"username"] fromChatroom:@"roomId" error:&error];
    // 將某成員加入黑名單
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager blockMembers:@[@"username"] fromChatroom:@"roomId" error:&error];
    // 將某成員移除黑名單
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager unblockMembers:@[@"username"] fromChatroom:@"roomId" error:&error];
    // 改變聊天室創(chuàng)建者時(shí)調(diào)用
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager updateChatroomOwner:@"roomId" newOwner:@"newOwner" error:&error];
    // 添加聊天室管理員
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager addAdmin:@"adminName" toChatroom:@"roomId" error:&error];
    // 移除聊天室管理員
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager removeAdmin:@"adminName" fromChatroom:@"roomId" error:&error];
    
    // 禁言聊天室成員
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager muteMembers:@[@"userName"] muteMilliseconds:100 aChatroomId:@"roomId" error:&error];
    
    // 解禁言聊天室成員
    EMError *error = nil;
    EMChatroom *room = [[EMClient sharedClient].roomManager unmuteMembers:@[@"userName"] fromChatroom:@"roomId" error:&error];
    // 添加dele <EMChatroomManagerDelegate>
    [[EMClient sharedClient].roomManager addDelegate:self delegateQueue:nil];
    // 移除dele
    [[EMClient sharedClient].roomManager removeDelegate:self];
    
    // 有用戶(hù)加入聊天室后調(diào)用
    - (void)userDidJoinChatroom:(EMChatroom *)aChatroom user:(NSString *)aUsername{}
    // 有用戶(hù)離開(kāi)聊天室后調(diào)用
    - (void)userDidLeaveChatroom:(EMChatroom *)aChatroom user:(NSString *)aUsername{}
    // 被踢出聊天室后調(diào)用
    - (void)didDismissFromChatroom:(EMChatroom *)aChatroom reason:(EMChatroomBeKickedReason)aReason{}
    // 有成員被禁言時(shí)調(diào)用
    - (void)chatroomMuteListDidUpdate:(EMChatroom *)aChatroom addedMutedMembers:(NSArray *)aMutes muteExpire:(NSInteger)aMuteExpire{}
    // 有成員被移除禁言列表時(shí)調(diào)用
    - (void)chatroomMuteListDidUpdate:(EMChatroom *)aChatroom removedMutedMembers:(NSArray *)aMutes{}
    // 有成員被加入管理員列表時(shí)調(diào)用
    - (void)chatroomAdminListDidUpdate:(EMChatroom *)aChatroom addedAdmin:(NSString *)aAdmin
    // 有成員被移出管理員列表時(shí)調(diào)用
    - (void)chatroomAdminListDidUpdate:(EMChatroom *)aChatroom removedAdmin:(NSString *)aAdmin
    // 聊天室創(chuàng)建者更新時(shí)調(diào)用
    - (void)chatroomOwnerDidUpdate:(EMChatroom *)aChatroom newOwner:(NSString *)aNewOwner oldOwner:(NSString *)aOldOwner{}
    // 聊天室公告有更新時(shí)調(diào)用
    - (void)chatroomAnnouncementDidUpdate:(EMChatroom *)aChatroom announcement:(NSString *)aAnnouncement{}

通話

    // 1.option配置
    EMCallOptions *options = [[EMClient sharedClient].callManager getCallOptions];
    // 當(dāng)對(duì)方不在線時(shí),是否給對(duì)方發(fā)送離線消息和推送,并等待對(duì)方回應(yīng)
    options.isSendPushIfOffline = NO;
    // 設(shè)置視頻分辨率:自適應(yīng)分辨率、352 * 288、640 * 480、1280 * 720
    options.videoResolution = EMCallVideoResolutionAdaptive;
    // 最大視頻碼率,范圍 50 < videoKbps < 5000, 默認(rèn)0, 0為自適應(yīng),建議設(shè)置為0
    options.maxVideoKbps = 0;
    // 最小視頻碼率
    options.minVideoKbps = 0;
    // 是否固定視頻分辨率,默認(rèn)為NO
    options.isFixedVideoResolution = NO;
    [[EMClient sharedClient].callManager setCallOptions:options];
    // 2.發(fā)起通話
    [[EMClient sharedClient].callManager startCall:EMCallTypeVideo remoteName:@"被呼叫的用戶(hù)" ext:nil completion:^(EMCallSession *aCallSession, EMError *aError) {
        if(!aError){
        }
    }];
    // 2.同意通話
    EMError *error = nil;
    error = [[EMClient sharedClient].callManager answerIncomingCall:@"sessionId"];
    // 3.結(jié)束通話
    [[EMClient sharedClient].callManager endCall:@"sessionId" reason:EMCallEndReasonHangup];
    /
     EMCallEndReasonHangup   = 0,   對(duì)方掛斷
    EMCallEndReasonNoResponse,      對(duì)方?jīng)]有響應(yīng)
    EMCallEndReasonDecline,         對(duì)方拒接
    EMCallEndReasonBusy,            對(duì)方占線
    EMCallEndReasonFailed,          失敗
    EMCallEndReasonUnsupported,     功能不支持
    EMCallEndReasonRemoteOffline,   對(duì)方不在線
     /
    
    //
    EMCallSession *callSession=[EMCallSession new];
    // 本地視頻
    callSession.localVideoView = [[EMCallLocalView alloc] initWithFrame:CGRectMake(0,0,0,0)];
    [self.view addSubview:callSession.localVideoView];
    // 對(duì)方視頻
    callSession.remoteVideoView = [[EMCallRemoteView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    // 縮放Mode
    callSession.remoteVideoView.scaleMode = EMCallViewScaleModeAspectFill;
    [self.view addSubview:_callSession.remoteVideoView];
    
     // 暫停語(yǔ)音數(shù)據(jù)傳輸
    [callSession pauseVideo];
    // 恢復(fù)語(yǔ)音數(shù)據(jù)傳輸
    [callSession resumeVideo];
    // 暫停視圖數(shù)據(jù)傳輸
    [callSession pauseVideo];
    // 恢復(fù)視頻數(shù)據(jù)傳輸
    [callSession resumeVideo];
    // 是否使用前置攝像頭,false:后置
    [callSession switchCameraPosition:true];
    // 添加dele  <EMCallManagerDelegate>
    [[EMClient sharedClient].callManager addDelegate:self delegateQueue:nil];
    // 移除dele
    [[EMClient sharedClient]removeDelegate:self];
    // 收到視頻請(qǐng)求后調(diào)用
    - (void)callDidReceive:(EMCallSession *)aSession
    // 統(tǒng)一通話后雙方都回調(diào)
    - (void)callDidConnect:(EMCallSession *)aSession
    // 對(duì)方同意通話后回調(diào)
    - (void)callDidAccept:(EMCallSession *)aSession
    // 通話結(jié)束(包括出現(xiàn)錯(cuò)誤)雙方都回調(diào)
    - (void)callDidEnd:(EMCallSession *)aSession reason:(EMCallEndReason)aReason error:(EMError *)aError{}
    // 對(duì)方中斷或者繼續(xù)數(shù)據(jù)流傳輸時(shí)調(diào)用
    - (void)callStateDidChange:(EMCallSession *)aSession type:(EMCallStreamingStatus)aType{}
    // 網(wǎng)絡(luò)狀態(tài)不穩(wěn)定時(shí)調(diào)用
    - (void)callNetworkDidChange:(EMCallSession *)aSession status:(EMCallNetworkStatus)aStatus{}

    // 離線dele <EMCallBuilderDelegate>
    [[EMClient sharedClient].callManager setBuilderDelegate:self];
    - (void)callRemoteOffline:(NSString *)aRemoteName{
        
        //
        NSString *text = [[EMClient sharedClient].callManager getCallOptions].offlineMessageText;
        EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:text];
        NSString *fromStr = [EMClient sharedClient].currentUsername;
        EMMessage *message = [[EMMessage alloc] initWithConversationID:aRemoteName from:fromStr to:aRemoteName body:body ext:@{@"em_apns_ext":@{@"em_push_title":text}}];
        message.chatType = EMChatTypeChat;
        
        [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
    }

多設(shè)備

    // 獲取當(dāng)前帳號(hào)在其他設(shè)備上的ID列表
    NSArray *otherPlatformIds = [[EMClient sharedClient].contactManager getSelfIdsOnOtherPlatformWithError:nil];
    if ([otherPlatformIds count] > 0) {
        NSString *chatter = otherPlatformIds[0];
        //獲取會(huì)話
        EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:chatter type:EMConversationTypeChat createIfNotExist:YES];
        
        //發(fā)送消息
        NSString *sendText = @"test";
        EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:sendText];
        NSString *from = [[EMClient sharedClient] currentUsername];
        EMMessage *message = [[EMMessage alloc] initWithConversationID:conversation.conversationId from:from to:chatter body:body ext:nil];
        message.chatType = EMChatTypeChat;
        [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
    }
    
    
    // <EMMultiDevicesDelegate>
    [[EMClient sharedClient] addMultiDevicesDelegate:self delegateQueue:nil];
    // 多設(shè)備收到好友時(shí)調(diào)用
    - (void)multiDevicesContactEventDidReceive:(EMMultiDevicesEvent)aEvent
username:(NSString *)aTarget
ext:(NSString *)aExt{
        NSString *message = [NSString stringWithFormat:@"%li-%@-%@", (long)aEvent, aTarget, aExt];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert.multi.contact", @"Contact Multi-devices") message:message delegate:self cancelButtonTitle:NSLocalizedString(@"ok", @"OK") otherButtonTitles:nil, nil];
        [alertView show];
    }
    // 多設(shè)備收到群組時(shí)調(diào)用
    - (void)multiDevicesGroupEventDidReceive:(EMMultiDevicesEvent)aEvent
groupId:(NSString *)aGroupId
ext:(id)aExt{
        NSString *message = [NSString stringWithFormat:@"%li-%@-%@", (long)aEvent, aGroupId, aExt];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"alert.multi.group", @"Group Multi-devices") message:message delegate:self cancelButtonTitle:NSLocalizedString(@"ok", @"OK") otherButtonTitles:nil, nil];
        [alertView show];
    }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 點(diǎn)擊查看原文 Web SDK 開(kāi)發(fā)手冊(cè) SDK 概述 網(wǎng)易云信 SDK 為 Web 應(yīng)用提供一個(gè)完善的 IM 系統(tǒng)...
    layjoy閱讀 14,314評(píng)論 0 15
  • 1)項(xiàng)目里面不需要環(huán)信SDK的太多功能,只是想要聊天和好友功能,其他都不用,那SDK一定要總是跟著更新么? a.環(huán)...
    DefaultYuan閱讀 26,804評(píng)論 17 59
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,379評(píng)論 4 61
  • android中如何顯示開(kāi)發(fā)者服務(wù)器上的昵稱(chēng)和頭像 http://www.imgeek.org/article/8...
    苦可樂(lè)閱讀 1,305評(píng)論 0 1
  • 來(lái)源于: Mr.pengge 圖像繪制總結(jié)
    huixiansheng閱讀 106評(píng)論 0 0

友情鏈接更多精彩內(nèi)容