李洪強iOS開發之-環信02.1_環信 SDK 2.x到3.0升級文檔

來源:互聯網
上載者:User

標籤:

李洪強iOS開發之-環信02.1_環信 SDK 2.x到3.0升級文檔SDK 2.x 至 3.0 升級指南環信 SDK 3.0 升級文檔

3.0 中的核心類為 EMClient 類,通過 EMClient 類可以擷取到 chatManager、groupManager、contactManager、roomManager對象。原來 2.0 版本的 SDK 很多方法提供了同步、非同步回調、非同步(block)三種方法,3.0 版只提供同步方法(async開頭的方法為非同步方法呼叫)。

例如:

//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版本,網路請求的方法只提供了同步方法- (EMError *)loginWithUsername:(NSString *)aUsername                      password:(NSString *)aPassword;

註冊回調,3.0 SDK 對功能進行了模組化,將不同功能回調封裝到不同模組。

//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];//訊息回調
使用升級替換指令碼

3.0 升級協助工具輔助(替換枚舉、屬性、方法名稱等):

python EMReplace.py replacePath

xcode 編譯提示工具:

//1. Xcode->build Phases//2. 添加一個新的Run Script//3. 填寫指令碼:python ${路徑}/EMChecker.py//編譯運行會有提示
代碼升級替換文檔

3.0 SDK 大部分代碼與 2.0 SDK 比較,邏輯沒有變化,為了統一修改了名稱。2.0 版本提供的非同步方法呼叫,對應的回調 3.0 不再支援(注意:3.0 只提供同步方法)。

入口的變化,2.0 版本 [EaseMob shareInstance] → 3.0 版本 [EMClient sharedClient]。

 

2.0版本 3.0版本
登入相關
2.0版本,當前登入的使用者資訊
[[[EaseMob sharedInstance] chatManager] loginInfo]
3.0版本,只提供當前登入帳號
[[EMClient sharedClient] currentUsername]
2.0版本,當前是否已有登入的使用者
[[[EaseMob sharedInstance] chatManager] isLoggedIn]
3.0版本
[[EMClient sharedClient] isLoggedIn]
2.0版本,是否連上聊天伺服器
[[[EaseMob sharedInstance] chatManager] isConnected]
3.0版本
[[EMClient sharedClient] isConnected]
2.0版本,將資料庫資料匯入新的資料庫
[[EaseMob sharedInstance].chatManager importDataToNewDatabase]
3.0版本,升級到SDK 3.0版本需要調用該方法,開發人員需要等該方法執行完後再進行資料庫查詢操作
[[EMClient sharedClient] dataMigrationTo3]
2.0版本,從資料庫擷取資訊
[[EaseMob sharedInstance].chatManager loadDataFromDatabase]
3.0版本不再支援
2.0版本,在聊天伺服器上建立帳號
- (BOOL)registerNewAccount:(NSString *)username password:(NSString *)password error:(EMError **)pError;
- (void)asyncRegisterNewAccount:(NSString *)username password:(NSString *)password;
- (void)asyncRegisterNewAccount:(NSString *)username password:(NSString *)password withCompletion:(void (^)(NSString *username,NSString *password,EMError *error))completion onQueue:(dispatch_queue_t)aQueue;
3.0版本,只提供同步方法
EMError *error = [[EMClient sharedClient] registerWithUsername:@"username"password:@"password"]
2.0版本,使用使用者名稱密碼登入聊天伺服器
- (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版本,只提供同步方法
- (EMError *)loginWithUsername:(NSString *)aUsername password:(NSString *)aPassword
//調用方法:EMError *error = [[EMClient sharedClient] loginWithUsername:@"username" password:@"password"]
2.0版本,登出當前登入使用者
- (NSDictionary *)logoffWithUnbindDeviceToken:(BOOL)isUnbind error:(EMError **)pError;
- (void)asyncLogoffWithUnbindDeviceToken:(BOOL)isUnbind;
- (void)asyncLogoffWithUnbindDeviceToken:(BOOL)isUnbind completion:(void (^)(NSDictionary *info, EMError *error))completion onQueue:(dispatch_queue_t)aQueue;
3.0版本,只提供同步方法
- (EMError *)logout:(BOOL)bIsUnbindDeviceToken;
//調用方法:EMError *error = [[EMClient sharedClient] logout:NO];
登入回調
2.0版本->EMChatManagerLoginDelegate 3.0版本->EMClientDelegate
使用者將要進行自動登入操作的回調
- (void)willAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;
使用者登入後的回調
- (void)didLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;
使用者登出後的回調
- (void)didLogoffWithError:(EMError *)error;
註冊新使用者後的回調
- (void)didRegisterNewAccount:(NSString *)username password:(NSString *)password error:(EMError *)error;
3.0版本不再支援的回調
2.0版本,使用者自動登入完成後的回調
- (void)didAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error;
3.0版本使用EMClientDelegate
- (void)didAutoLoginWithError:(EMError *)error;
2.0版本,當前登入帳號在其它裝置登入時的通知回調
- (void)didLoginFromOtherDevice;
2.0版本,當前登入帳號已經被從伺服器端刪除
- (void)didRemovedFromServer;
3.0版本使用EMClientDelegate,回調行為與2.0保持一致
2.0版本,將要發起自動重連操作的回調
- (void)willAutoReconnect;
自動重連操作完成後的回調
- (void)didAutoReconnectFinishedWithError:(NSError *)error;
3.0版本使用EMClientDelegate
- (void)didConnectionStateChanged:(EMConnectionState)connectionState;
訊息相關
2.0版本IChatManagerChat 3.0版本IEMChatManager
2.0版本,發送訊息的方法
- (EMMessage *)sendMessage:(EMMessage *)message progress:(id)progress error:(EMError **)pError;
- (EMMessage *)asyncSendMessage:(EMMessage *)message progress:(id)progress;
- (EMMessage *)asyncSendMessage:(EMMessage *)message progress:(id)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;
3.0版本
- (void)asyncSendMessage:(EMMessage *)aMessage progress:(void (^)(int progress))aProgress completion:(void (^)(EMMessage *message, EMError *error))aProgressCompletion;
//調用: //[[EMClient sharedClient].chatManager asyncSendMessage:message progress:nil completion:^(EMMessage *aMessage, EMError *aError) {}];
2.0版本,發送一個"已讀訊息"(在UI上顯示了或者閱後即焚的銷毀的時候發送)的回執到伺服器
- (void)sendReadAckForMessage:(EMMessage *)message;
3.0版本
- (void)asyncSendReadAckForMessage:(EMMessage *)message;
//調用: //[[EMClient sharedClient].chatManager asyncSendReadAckForMessage:message];
2.0版本,重新發送某一條訊息
- (EMMessage *)resendMessage:(EMMessage *)message progress:(id)progress error:(EMError **)pError;
- (EMMessage *)asyncResendMessage:(EMMessage *)message progress:(id)progress;
- (EMMessage *)asyncResendMessage:(EMMessage *)message progress:(id)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;
3.0版本
*/ - (void)asyncResendMessage:(EMMessage *)aMessage progress:(void (^)(int progress))aProgressCompletion completion:(void (^)(EMMessage *message, EMError *error))aCompletion;
//調用: //[[EMClient sharedClient].chatManager asyncResendMessage:message progress:nil completion:^(EMMessage *aMessage, EMError *aError) {}];
聊天室相關
2.0版本 3.0版本
2.0版本,聊天室的主題
@property (nonatomic, strong, readonly) NSString *chatroomSubject;
3.0版本
@property (nonatomic, copy, readonly) NSString *subject;
2.0版本,聊天室的描述
@property (nonatomic, strong, readonly) NSString *chatroomDescription;
3.0版本
@property (nonatomic, copy, readonly) NSString *description;
2.0版本,聊天室的最大人數
@property (nonatomic, readonly) NSInteger chatroomMaxOccupantsCount;
3.0版本
@property (nonatomic, readonly) NSInteger maxOccupantsCount;
群組相關
2.0版本 3.0版本
2.0版本,從資料庫擷取與登入者相關的群組
- (NSArray *)loadAllMyGroupsFromDatabaseWithAppend2Chat:(BOOL)append2Chat;
3.0版本
- (NSArray *)loadAllMyGroupsFromDB;
//調用:[[EMClient sharedClient].groupManager loadAllMyGroupsFromDB];
2.0版本,建立群組
- (EMGroup *)createGroupWithSubject:(NSString *)subject description:(NSString *)description invitees:(NSArray *)invitees initialWelcomeMessage:(NSString *)welcomeMessage styleSetting:(EMGroupStyleSetting *)styleSetting error:(EMError **)pError;
- (void)asyncCreateGroupWithSubject:(NSString *)subject description:(NSString *)description invitees:(NSArray *)invitees initialWelcomeMessage:(NSString *)welcomeMessage styleSetting:(EMGroupStyleSetting *)styleSetting;
- (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;
3.0版本
- (EMGroup *)createGroupWithSubject:(NSString *)aSubject description:(NSString *)aDescription invitees:(NSArray *)aInvitees message:(NSString *)aMessage setting:(EMGroupOptions *)aSetting error:(EMError **)pError;
//調用: //EMError *error = nil; //EMGroup *group = [[EMClient sharedClient].groupManager createGroupWithSubject:@"subject" description:@"desc" invitees:source message:@"message" setting:setting error:&error];
2.0版本,建立匿名群組 3.0版本不再提供
2.0版本,加入一個匿名公開群組 3.0版本不再提供
2.0版本,退出群組(需要非owner的許可權)
- (EMGroup *)leaveGroup:(NSString *)groupId error:(EMError **)pError;
- (void)asyncLeaveGroup:(NSString *)groupId;
- (void)asyncLeaveGroup:(NSString *)groupId completion:(void (^)(EMGroup *group, EMGroupLeaveReason reason, EMError *error))completion onQueue:(dispatch_queue_t)aQueue;
3.0版本
- (EMGroup *)leaveGroup:(NSString *)aGroupId error:(EMError **)pError;
//調用: //EMError *error = nil; //[[EMClient sharedClient].groupManager leaveGroup:@"groupId" error:&error];
2.0版本,解散群組,需要owner許可權
- (EMGroup *)destroyGroup:(NSString *)groupId error:(EMError **)pError;
- (void)asyncDestroyGroup:(NSString *)groupId;
- (void)asyncDestroyGroup:(NSString *)groupId completion:(void (^)(EMGroup *group, EMGroupLeaveReason reason, EMError *error))completion onQueue:(dispatch_queue_t)aQueue;
3.0版本
- (EMGroup *)destroyGroup:(NSString *)aGroupId error:(EMError **)pError;
//調用: //EMError *error = nil; //[[EMClient sharedClient].groupManager destroyGroup:@"groupId" error:&error];

李洪強iOS開發之-環信02.1_環信 SDK 2.x到3.0升級文檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.