差别
这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 后一修订版 两侧同时换到之后的修订记录 | ||
im:ios:sdk:upgradeguide [2018/09/25 04:52] jk 创建 |
im:ios:sdk:upgradeguide [2018/09/25 06:30] jk |
||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== SDK 2.x 至 3.x 升级指南 ====== | + | ====== SDK 2.x 至 3.0 升级指南 ====== |
----- | ----- | ||
+ | =====环信 SDK 3.0 升级文档===== | ||
- | ===== API 大致变动介绍 ===== | + | 3.0 中的核心类为 EMClient 类,通过 EMClient 类可以获取到 chatManager、groupManager、contactManager、roomManager对象。原来 2.0 版本的 SDK 很多方法提供了同步、异步回调、异步(block)三种方法,3.0 版只提供同步方法和异步block方法。 |
- | 3.0 中的核心类为 EMClient 类,通过 emclient 类可以获取到 chatmanager、groupmanager、contactmanager、chatroommanager 等 manager 对象,此外和这些 manager 不太相关的方法基本 EMClient 类里面,如登录、设置连接监听等方法。message 里的成员变量的获取都变成 getXXX 获取。 | + | 例如: |
- | 从 2.x 升级到 3.0,大部分的变动只需要改变 API 名称就可以了,但是少部分地方因为架构等原因需要一些稍复杂的改动。 | + | <code objc> |
+ | //2.0版本登录方法,提供了同步、异步、异步block三种方法 | ||
+ | - (NSDictionary *)loginWithUsername:(NSString *)username | ||
+ | password:(NSString *)password | ||
+ | error:(EMError **)pError; | ||
+ | - (void)asyncLoginWithUsername:(NSString *)username | ||
+ | password:(NSString *)password; | ||
+ | |||
+ | - (void)asyncLoginWithUsername:(NSString *)username | ||
+ | password:(NSString *)password | ||
+ | completion:(void (^)(NSDictionary *loginInfo, EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue; | ||
+ | |||
+ | //3.0版本,网络请求的方法提供了同步方法和异步block方法 | ||
+ | - (EMError *)loginWithUsername:(NSString *)aUsername | ||
+ | password:(NSString *)aPassword; | ||
+ | |||
+ | - (void)loginWithUsername:(NSString *)aUsername | ||
+ | password:(NSString *)aPassword | ||
+ | completion:(void (^)(NSString *aUsername, EMError *aError))aCompletionBlock; | ||
+ | |||
+ | </code> | ||
+ | |||
+ | 注册回调,3.0 SDK 对功能进行了模块化,将不同功能回调封装到不同模块。 | ||
+ | |||
+ | <code objc> | ||
+ | //2.0版本回调注册 | ||
+ | [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil]; | ||
+ | |||
+ | //3.0版本回调注册需要分模块注册 | ||
+ | [[EMClient sharedClient] addDelegate:self delegateQueue:nil];//登录相关的回调 | ||
+ | [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];//群组回调 | ||
+ | [[EMClient sharedClient].contactManager addDelegate:self delegateQueue:nil];//联系人回调 | ||
+ | [[EMClient sharedClient].roomManager addDelegate:self delegateQueue:nil];//聊天室回调 | ||
+ | [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];//消息回调 | ||
+ | </code> | ||
+ | |||
+ | ===== 使用升级替换脚本 ===== | ||
+ | |||
+ | 3.0 升级辅助工具(替换枚举、属性、方法名称等): | ||
+ | |||
+ | <code> | ||
+ | python EMReplace.py replacePath | ||
+ | </code> | ||
+ | |||
+ | xcode 编译提示工具: | ||
+ | |||
+ | <code> | ||
+ | //1. Xcode->build Phases | ||
+ | //2. 添加一个新的Run Script | ||
+ | //3. 填写脚本:python ${路径}/EMChecker.py | ||
+ | //编译运行会有提示 | ||
+ | </code> | ||
+ | |||
+ | =====代码升级替换文档===== | ||
+ | |||
+ | 3.0 SDK 大部分代码与 2.0 SDK 比较,逻辑没有变化,为了统一修改了名称。 | ||
+ | |||
+ | 入口的变化,2.0 版本 [EaseMob shareInstance] -> 3.0 版本 [EMClient sharedClient]。 | ||
- | 这里先列出API大概的变动列表: | ||
- | |||
<html> | <html> | ||
<table cellspacing="0" border="1"> | <table cellspacing="0" border="1"> | ||
- | <tr> | ||
- | <th>SDK2.x</th> | ||
- | <th style="color:red;">SDK3.0</th> | ||
- | </tr> | ||
<tr> | <tr> | ||
- | <th style="text-align:center;" colspan="2">登录初始化相关</th> | + | <th></br>2.0版本 EaseMob</br></th> |
+ | <th style="color:red;"></br>3.0版本 EMClient</th> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChat</td> | + | <th style="text-align:center;" colspan="2"></br>登录相关</th> |
- | <td>EMClient,emchat里之前的方法基本都在此类里</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatManager、EMGroupManger等manager类</td> | + | <th></br>当前登录的用户信息</br>[[[EaseMob sharedInstance] chatManager] loginInfo];</th> |
- | <td>都通过EMClient类获取,如:EMClient.getInstance().chatManager()</td> | + | <th></br>只提供当前登录账号</br>[[EMClient sharedClient] currentUsername];</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChat.getInstance().init(context);</td> | + | <th></br>当前是否已有登录的用户</br>[[[EaseMob sharedInstance] chatManager] isLoggedIn];</th> |
- | <td>EMClient.getInstance().init(appContext, options); | + | <th></br>当前是否已有登录的用户</br>[[EMClient sharedClient] isLoggedIn];</th> |
- | options需要初始化的适合一并传入</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatOptions,通过chatmanager获取到任何直接设置其值</td> | + | <th></br>是否连上聊天服务器</br>[[[EaseMob sharedInstance] chatManager] isConnected];</th> |
- | <td>EMOptions,通过new创建得到,设置其成员的值后,调用init方法时传入此options</td> | + | <th></br>是否连上聊天服务器</br>[[EMClient sharedClient] isConnected];</br></th> |
- | </tr> | + | </tr> |
<tr> | <tr> | ||
- | <td>options.setUseRoster()</td> | + | <th></br>将数据库数据导入新的数据库</br>[[EaseMob sharedInstance].chatManager importDataToNewDatabase];</th> |
- | <td>无,登录的时候SDK默认不会获取好友</td> | + | <th></br>升级到SDK 3.0版本需要调用该方法,开发者需要等该方法执行完后再进行数据库查询操作</br>[[EMClient sharedClient] dataMigrationTo3];</th> |
- | </tr> | + | </tr> |
<tr> | <tr> | ||
- | <td>Chatmanager里的setGCMProjectNumber方法移到EMClient里</td> | + | <th></br>从数据库获取信息</br>[[EaseMob sharedInstance].chatManager loadDataFromDatabase];</th> |
- | <td>EMClient.getInstance().setGCMProjectNumber(projectNumber);同理,设置第三方推送配置的方法也在此类里</td> | + | <th></br>分别从不同模块获取</br>[[EMClient sharedClient].chatManager getAllConversations];</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChat.getInstance().setAutoLogin(false)</td> | + | <th></br>在聊天服务器上创建账号</br>- (BOOL)registerNewAccount:(NSString *)username password:(NSString *)password error:(EMError **)pError;</br>- (void)asyncRegisterNewAccount:(NSString *)username password:(NSString *)password;</br>- (void)asyncRegisterNewAccount:(NSString *)username password:(NSString *)password withCompletion:(void (^)(NSString *username,NSString *password,EMError *error))completion onQueue:(dispatch_queue_t)aQueue;</th> |
- | <td>初始化通过option.setAutoLogin(false)设置</td> | + | <th></br>在聊天服务器上创建账号</br>[[EMClient sharedClient] registerWithUsername:@"username"password:@"password"];</br>[[EMClient sharedClient] registerWithUsername:@"username"password:@"password" completion:block];</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChat.getInstance().isLoggedIn()</td> | + | <th></br>使用用户名密码登录聊天服务器</br>- (NSDictionary *)loginWithUsername:(NSString *)username |
- | <td>EMClient.getInstance().isLoggedInBefore()</td> | + | password:(NSString *)password |
- | </tr> | + | error:(EMError **)pError;</br>- (void)asyncLoginWithUsername:(NSString *)username |
+ | password:(NSString *)password;</br>- (void)asyncLoginWithUsername:(NSString *)username | ||
+ | password:(NSString *)password | ||
+ | completion:(void (^)(NSDictionary *loginInfo, EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>使用用户名密码登录聊天服务器</br>[[EMClient sharedClient] loginWithUsername:@"username" password:@"password"];</br>[[EMClient sharedClient] loginWithUsername:@"username" password:@"password" completion:block];</th> | ||
+ | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatManager.getInstance().logout()</td> | + | <th></br>注销当前登录用户</br>- (NSDictionary *)logoffWithUnbindDeviceToken:(BOOL)isUnbind |
- | <td>EMClient.getInstance().logout()</td> | + | error:(EMError **)pError;</br>- (void)asyncLogoffWithUnbindDeviceToken:(BOOL)isUnbind;</br>- (void)asyncLogoffWithUnbindDeviceToken:(BOOL)isUnbind |
+ | completion:(void (^)(NSDictionary *info, EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>注销当前登录用户</br>[[EMClient sharedClient] logout:NO];</br>[[EMClient sharedClient] logout:NO completionblock];</th> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatmanager.getInstance().createAccountOnServer()</td> | + | <th style="text-align:center;" colspan="2"></br>登录回调</th> |
- | <td>EMClient.getInstance().createAccount()</td> | + | |
</tr> | </tr> | ||
- | <th style="text-align:center;" colspan="2">连接状态相关</th> | + | <tr> |
- | <tr> | + | <th></br>2.0版本 EMChatManagerLoginDelegate</br></th> |
- | <td>EMChatManager.getInstance(). | + | <th style="color:red;"></br>3.0版本 EMClientDelegate</br></th> |
- | addConnectionListener(connectionListener)</td> | + | |
- | <td>EMClient.getInstance().addConnectionListener(connectionListener);同理unregister方法调用removeConnectionListener</td></td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatManager.getInstance().isConnected()</td> | + | <th></br>用户将要进行自动登录操作</br>- (void)willAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;</br>用户登录完成</br>- (void)didLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;</br>用户注销完成</br>- (void)didLogoffWithError:(EMError *)error;</br>注册新用户后的回调</br>- (void)didRegisterNewAccount:(NSString *)username |
- | <td>EMClient.getInstance().isConnected()</td> | + | password:(NSString *)password |
+ | error:(EMError *)error;</th> | ||
+ | <th></br>不再支持相关回调</th> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <th style="text-align:center;" colspan="2">消息相关</th> | + | <th></br>用户自动登录完成</br>- (void)didAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;</th> |
- | </tr> | + | <th></br>用户自动登录完成</br>- (void)autoLoginDidCompleteWithError:(EMError *)error;</th> |
- | <tr> | + | |
- | <td>EMMessage</td> | + | |
- | <td>之前的public的成员变量都只能通过getXxx()的方式获取</td> | + | |
- | </tr> | + | |
- | <tr> | + | |
- | <td>MessageBody: TextMessageBody、VideoMessageBody等</td> | + | |
- | <td>都需要在前面加上EM,如:TextMessageBody->EMTextMessageBody</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMEventListener</td> | + | <th></br>当前登录账号在其它设备登录</br>- (void)didLoginFromOtherDevice;</th> |
- | <td>EMMessageListener,需要注意的是,3.0 的消息没有离线消息的回调,不区分离线消息和在线消息</td> | + | <th></br>当前登录账号在其它设备登录</br>- (void)userAccountDidLoginFromOtherDevice;</th> |
- | </tr> | + | </tr> |
<tr> | <tr> | ||
- | <td>EMChatManager.getInstance().registerEventListener</td> | + | <th></br>当前登录账号已经被从服务器端删除</br>- (void)didRemovedFromServer;</th> |
- | <td>EMClient.getInstance().chatManager().addMessageListener,移除监听调用removeMessageListener</td> | + | <th></br>当前登录账号已经被从服务器端删除</br>- (void)userAccountDidRemoveFromServer;</th> |
- | </tr> | + | |
- | <tr> | + | |
- | <td>conversation.getMsgCount()</td> | + | |
- | <td>无,使用conversation.getAllMessages().size取到count</td> | + | |
- | </tr> | + | |
- | <tr> | + | |
- | <td>conversation.loadMoreGroupMsgFromDB()</td> | + | |
- | <td>无,都使用conversation.loadMoreMsgFromDB()</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatmanager.getInstance().sendMessage(msg, callback)</td> | + | <th></br>将要发起自动重连操作的回调</br>- (void)willAutoReconnect;</br>自动重连操作完成后的回调</br>- (void)didAutoReconnectFinishedWithError:(NSError *)error;</th> |
- | <td>无callback,通过message.setMessageStatusCallback(EMCallBack callback)获取消息发送状态</td> | + | <th></br>连接状态发生变化</br>- (void)didConnectionStateChanged:(EMConnectionState)connectionState;</th> |
- | </tr> | + | |
- | <tr> | + | |
- | <td>conversation.addMessage(message)</td> | + | |
- | <td>无此方法,发送消息之前无需调用此方法</td> | + | |
- | </tr> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>conversation.getMessage(Pos);</td> | + | <th style="text-align:center;" colspan="2"></br>消息相关</th> |
- | <td>无,重发消息的时候需要传message对象作为intent的参数</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatmanager.getInstance().asyncFetchMessage()</td> | + | <th></br>2.0版本 IChatManagerChat IChatManagerDelegate</th> |
- | <td>语音消息调用EMClient.getInstance().chatManager().downloadAttachment();图片、视频消息等自动下载缩略图的消息调用downloadThumbnail()方法</td> | + | <th style="color:red;"></br>3.0版本 IEMChatManager EMChatManagerDelegate</th> |
+ | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatManager.getInstance().clearConversation</td> | + | <th></br>发送消息</br>- (EMMessage *)sendMessage:(EMMessage *)message |
- | <td>无,使用EMClient.getInstance().deleteConversation方法即可</td> | + | progress:(id<IEMChatProgressDelegate>)progress |
- | </tr> | + | error:(EMError **)pError;</br>- (EMMessage *)asyncSendMessage:(EMMessage *)message |
+ | progress:(id<IEMChatProgressDelegate>)progress;</br>- (EMMessage *)asyncSendMessage:(EMMessage *)message | ||
+ | progress:(id<IEMChatProgressDelegate>)progress | ||
+ | prepare:(void (^)(EMMessage *message, | ||
+ | EMError *error))prepare | ||
+ | onQueue:(dispatch_queue_t)aPrepareQueue | ||
+ | completion:(void (^)(EMMessage *message, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aCompletionQueue;</th> | ||
+ | <th></br>发送消息</br>[IEMChatManager sendMessage:progress:completion:];</th> | ||
+ | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatManager.getInstance().deleteAllConversation();</td> | + | <th></br>发送已读回执到服务器</br>- (void)sendReadAckForMessage:(EMMessage *)message;</th> |
- | <td>无,for循环调用删除会话方法即可</td> | + | <th></br>发送已读回执到服务器</br>[IEMChatManager sendMessageReadAck:completion:];</th> |
- | </tr> | + | |
- | <tr> | + | |
- | <th style="text-align:center;" colspan="2">群组聊天室相关</th> | + | |
- | </tr> | + | |
- | <tr> | + | |
- | <td>EMGroup不再继承自EMContact</td> | + | |
- | <td>-</td> | + | |
- | </tr> | + | |
- | <tr> | + | |
- | <td>创建群组</td> | + | |
- | <td>EMClient.getInstance().groupManager().createGroup(groupName, desc, allMembers, reason, option); | + | |
- | 具体参数的意思请参考群组管理文档</td> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMGroupManager.getInstance(). | + | <th></br>重新发送消息</br>- (EMMessage *)resendMessage:(EMMessage *)message |
- | createOrUpdateLocalGroup(group);</td> | + | progress:(id<IEMChatProgressDelegate>)progress |
- | <td>无,调用getGroupFromServer方法时,会自动更新本地有记录的群组</td> | + | error:(EMError **)pError;</br>- (EMMessage *)asyncResendMessage:(EMMessage *)message |
+ | progress:(id<IEMChatProgressDelegate>)progress;</br>- (EMMessage *)asyncResendMessage:(EMMessage *)message | ||
+ | progress:(id<IEMChatProgressDelegate>)progress | ||
+ | prepare:(void (^)(EMMessage *message, | ||
+ | EMError *error))prepare | ||
+ | onQueue:(dispatch_queue_t)aPrepareQueue | ||
+ | completion:(void (^)(EMMessage *message, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aCompletionQueue;</th> | ||
+ | <th></br>重新发送消息</br>[IEMChatManager resendMessage:progress:completion:]</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <th style="text-align:center;" colspan="2"></br>聊天室相关</th> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMGroupManager.getInstance().getGroupsFromServer()</td> | + | <th></br>2.0版本 IChatManagerChatroom IChatManagerDelegate</th> |
- | <td>EMClient.getInstance().groupManager().getJoinedGroupsFromServer()</td> | + | <th style="color:red;"></br>3.0版本 IEMChatroomManager EMChatroomManagerDelegate EMChatroomOptions</th> |
- | </tr> | + | </tr> |
<tr> | <tr> | ||
- | <td>EMGroupManager.getInstance().exitFromGroup()</td> | + | <th></br>主题</br>[EMChatroom chatroomSubject];</th> |
- | <td>EMClient.getInstance().groupManager().leaveGroup()</td> | + | <th></br>主题</br>[EMChatroom subject];</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMGroupManager.getInstance().exitAndDeleteGroup()</td> | + | <th></br>描述</br>[EMChatroom chatroomDescription];</th> |
- | <td>EMClient.getInstance().groupManager().destroyGroup()</td> | + | <th></br>描述</br>[EMChatroom description];</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>Chatroom相关的api</td> | + | <th></br>最大人数</br>[EMChatroom chatroomMaxOccupantsCount];</th> |
- | <td>都移到EMChatRoomManager类,chatroommanager的实例获取方法为EMClient.getInstance().chatroomManager()</td> | + | <th></br>最大人数</br>[EMChatroom maxOccupantsCount];</th> |
- | </tr> | + | |
- | <tr> | + | |
- | <th style="text-align:center;" colspan="2">用户相关</th> | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
- | <td>EMContact::setUsername()</td> | + | <th style="text-align:center;" colspan="2"></br>群组相关</th> |
- | <td>无,需要在new出emcontact对象时传入username</td> | + | |
</tr> | </tr> | ||
- | <tr> | ||
- | <td>getCurrentUser()移到EMClient类里</td> | ||
- | <td>EMClient.getInstance().getCurrentUser()</td> | ||
- | </tr> | ||
<tr> | <tr> | ||
- | <td>EMChatmanager.getInstance().updateCurrentUserNick()</td> | + | <th></br>2.0版本 IChatManagerGroup IChatManagerDelegate</th> |
- | <td>EMClient.getInstance().updateCurrentUserNick()</td> | + | <th style="color:red;"></br>3.0版本 IEMGroupManager EMGroupManagerDelegate</th> |
- | </tr> | + | </tr> |
- | <tr> | + | <tr> |
- | <td>EMContactManager.getInstance().getContactUserNames()</td> | + | <th></br>从数据库获取与登录者相关的群组</br>- (NSArray *)loadAllMyGroupsFromDatabaseWithAppend2Chat:(BOOL)append2Chat;</th> |
- | <td>EMClient.getInstance().contactManager().getAllContactsFromServer()</td> | + | <th></br>获取用户所有群组</br>[IEMGroupManager getJoinedGroups];</th> |
</tr> | </tr> | ||
- | <tr> | + | <tr> |
- | <td>EMContactManager.getInstance(). | + | <th></br>创建群组</br>- (EMGroup *)createGroupWithSubject:(NSString *)subject |
- | getBlackListUsernamesFromServer()</td> | + | description:(NSString *)description |
- | <td>EMClient.getInstance().contactManager().getBlackListFromServer()</td> | + | invitees:(NSArray *)invitees |
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting | ||
+ | error:(EMError **)pError;</br>- (void)asyncCreateGroupWithSubject:(NSString *)subject | ||
+ | description:(NSString *)description | ||
+ | invitees:(NSArray *)invitees | ||
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting;</br>- (void)asyncCreateGroupWithSubject:(NSString *)subject | ||
+ | description:(NSString *)description | ||
+ | invitees:(NSArray *)invitees | ||
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting | ||
+ | completion:(void (^)(EMGroup *group, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>3.0版本</br>[IEMGroupManager createGroupWithSubject:description:invitees:message:setting:error:];</br>[IEMGroupManager createGroupWithSubject:description:invitees:message:setting:completion:];</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <th></br>创建匿名群组</br>- (EMGroup *)createAnonymousGroupWithSubject:(NSString *)subject | ||
+ | description:(NSString *)description | ||
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | nickname:(NSString *)nickname | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting | ||
+ | error:(EMError **)pError;</br>- (void)asyncCreateAnonymousGroupWithSubject:(NSString *)subject | ||
+ | description:(NSString *)description | ||
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | nickname:(NSString *)nickname | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting;</br>- (void)asyncCreateAnonymousGroupWithSubject:(NSString *)subject | ||
+ | description:(NSString *)description | ||
+ | initialWelcomeMessage:(NSString *)welcomeMessage | ||
+ | nickname:(NSString *)nickname | ||
+ | styleSetting:(EMGroupStyleSetting *)styleSetting | ||
+ | completion:(void (^)(EMGroup *group, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>不再提供</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <th></br>加入一个匿名公开群组</br>- (EMGroup *)joinAnonymousPublicGroup:(NSString *)groupId | ||
+ | nickname:(NSString *)nickname | ||
+ | error:(EMError **)pError;</br>- (void)asyncJoinAnonymousPublicGroup:(NSString *)groupId | ||
+ | nickname:(NSString *)nickname;</br>- (void)asyncJoinAnonymousPublicGroup:(NSString *)groupId | ||
+ | nickname:(NSString *)nickname | ||
+ | completion:(void (^)(EMGroup *group, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>不再提供</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <th></br>退出群组</br>- (EMGroup *)leaveGroup:(NSString *)groupId | ||
+ | error:(EMError **)pError;</br>- (void)asyncLeaveGroup:(NSString *)groupId;</br>- (void)asyncLeaveGroup:(NSString *)groupId | ||
+ | completion:(void (^)(EMGroup *group, | ||
+ | EMGroupLeaveReason reason, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>退出群组</br>[IEMGroupManager leaveGroup:error:];</br>[IEMGroupManager leaveGroup:completion:];</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <th></br>解散群组</br>- (EMGroup *)destroyGroup:(NSString *)groupId | ||
+ | error:(EMError **)pError;</br>- (void)asyncDestroyGroup:(NSString *)groupId;</br>- (void)asyncDestroyGroup:(NSString *)groupId | ||
+ | completion:(void (^)(EMGroup *group, | ||
+ | EMGroupLeaveReason reason, | ||
+ | EMError *error))completion | ||
+ | onQueue:(dispatch_queue_t)aQueue;</th> | ||
+ | <th></br>解散群组</br>[IEMGroupManager destroyGroup:];</br>[IEMGroupManager destroyGroup: | ||
+ | finishCompletion:];</th> | ||
</tr> | </tr> | ||
- | <tr> | + | </table> |
- | <td>EMContactManager.getInstance().deleteUserFromBlackList()</td> | + | |
- | <td>EMClient.getInstance().contactManager().removeUserFromBlackList()</td> | + | |
- | </tr> | + | |
- | </table> | + | |
</html> | </html> | ||
- | |||
- | **消息接发对于以前通过 conversation.addConversation() 方法,然后在 adapter 中发送消息的开发者来说变动稍微有点大,这里再单独列出来修改方法:** | ||
- | | ||
- | 首先把 conversation.addMessage(message) 删除掉,然后调用 sendmessage 方法,在 messageadapter 显示消息的地方,不再调用 sendmessage 方法,adapter 里只是根据消息的状态显示相应的 UI 即可,通过调用 message.setMessageStatusCallback(messageReceiveCallback),监听消息是否发送成功等,这里以发送文字消息作为示例: | ||
- | |||
- | <code java> | ||
- | protected void sendMessage(EMMessage message){ | ||
- | if(chatFragmentListener != null){ | ||
- | //设置扩展属性 | ||
- | chatFragmentListener.onSetMessageAttributes(message); | ||
- | } | ||
- | // 如果是群聊,设置chattype,默认是单聊 | ||
- | if (chatType == EaseConstant.CHATTYPE_GROUP){ | ||
- | message.setChatType(ChatType.GroupChat); | ||
- | }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){ | ||
- | message.setChatType(ChatType.ChatRoom); | ||
- | } | ||
- | //发送消息 | ||
- | EMClient.getInstance().chatManager().sendMessage(message); | ||
- | //刷新ui | ||
- | messageList.refreshSelectLast(); | ||
- | } | ||
- | </code> | ||
- | |||
- | 在显示消息的 adpater 中,根据消息状态显示相应 UI 即可。 | ||
- | |||
- | <code java> | ||
- | protected void handleTextMessage() { | ||
- | if (message.direct() == EMMessage.Direct.SEND) { | ||
- | setMessageSendCallback(); | ||
- | switch (message.status()) { | ||
- | case CREATE: | ||
- | progressBar.setVisibility(View.GONE); | ||
- | statusView.setVisibility(View.VISIBLE); | ||
- | break; | ||
- | case SUCCESS: // 发送成功 | ||
- | progressBar.setVisibility(View.GONE); | ||
- | statusView.setVisibility(View.GONE); | ||
- | break; | ||
- | case FAIL: // 发送失败 | ||
- | progressBar.setVisibility(View.GONE); | ||
- | statusView.setVisibility(View.VISIBLE); | ||
- | break; | ||
- | case INPROGRESS: // 发送中 | ||
- | progressBar.setVisibility(View.VISIBLE); | ||
- | statusView.setVisibility(View.GONE); | ||
- | break; | ||
- | default: | ||
- | break; | ||
- | } | ||
- | }else{ | ||
- | if(!message.isAcked() && message.getChatType() == ChatType.Chat){ | ||
- | try { | ||
- | EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); | ||
- | } catch (HyphenateException e) { | ||
- | e.printStackTrace(); | ||
- | } | ||
- | } | ||
- | } | ||
- | } | ||
- | </code> | ||
- | |||
- | ===== 3.x 后续API改动 ===== | ||
- | |||
- | * [[im:200androidclientintegration:3.1.5apichange|3.1.5api修改]] | ||
- | * [[im:200androidclientintegration:3.2.3apichange|3.2.3api修改]] | ||
- | * [[im:200androidclientintegration:3.3.0apichange|3.3.0api修改]] | ||
行 258: | 行 294: | ||
<WRAP group> | <WRAP group> | ||
<WRAP half column> | <WRAP half column> | ||
- | 上一页:[[im:200androidclientintegration:120androidsdkjavadoc|Android SDK API Doc]] | + | 上一页:[[im:ios:sdk:quickstart|iOS SDK 快速集成]] |
</WRAP> | </WRAP> | ||
<WRAP half column> | <WRAP half column> | ||
- | 下一页:[[im:200androidclientintegration:160androidreleasenote|Android SDK 更新日志]] | + | 下一页:[[im:ios:sdk:apidoc|iOS SDK API Doc]] |
</WRAP> | </WRAP> | ||
</WRAP> | </WRAP> | ||