日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

环信集成 2---基于环信Demo3.0,实现单聊功能

發(fā)布時間:2024/4/13 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 环信集成 2---基于环信Demo3.0,实现单聊功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這幾天在做環(huán)信,所以把環(huán)信相關(guān)的東西拿過來,做個系統(tǒng)點的東西

?

?

注意:

  • 這里Demo集成的是帶有實時語音功能的(libEaseMobClientSDK.a)。
  • 環(huán)信庫是直接拖拽EaseMobSDK文件夾到項目內(nèi)的,沒有使用pod管理。
  • 最終效果


    15

    添加環(huán)信SDK

  • 下載環(huán)信SDK 2.2.1
    鏈接地址

    1
  • 添加EaseMobSDK到項目中,并添加依賴庫。這里需要注意的地方:libEaseMobClientSDKLite.a不包含實時語音功能,libEaseMobClientSDK.a包含所有功能。必須要刪掉一個,否則會報錯。這里刪除libEaseMobClientSDKLite.a。
  • 添加依賴庫。參見官方文檔

    2

    3
  • 新創(chuàng)建一個pch,并在Build Settings中添加配置。
    在pch中,導(dǎo)入頭文件。 #ifndef PrefixHeader_pch #define PrefixHeader_pch #import "EaseMob.h" #endif /* PrefixHeader_pch */
    4
  • 添加環(huán)信EaseUI

  • 導(dǎo)入EaseUI到項目中,并實現(xiàn)基礎(chǔ)的登陸功能。
    找到Demo3.0的EaseUI目錄,然后將如下文件,拖拽到項目中。并在pch文件中引入EaseUI.h #ifndef PrefixHeader_pch #define PrefixHeader_pch #import "EaseMob.h" #import "EaseUI.h" #endif /* PrefixHeader_pch */
    5

    6
  • 在AppDelegate.m中注冊環(huán)信的SDK和UI。
  • 在StoryBoard中新增一個按鈕,并給予登陸方法。然后在方法中實現(xiàn)登陸功能。當?shù)顷懗晒?發(fā)送通知。收到通知后,跳轉(zhuǎn)到UI提供的EaseMessageViewController界面。
  • 其中APPDelegate中文件內(nèi)容

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//注冊SDK[[EaseMob sharedInstance] registerSDKWithAppKey:@"easemob-demo#chatdemoui" apnsCertName:nil];//注冊UI[[EaseSDKHelper shareHelper] easemobApplication:applicationdidFinishLaunchingWithOptions:launchOptionsappkey:@"easemob-demo#chatdemoui"apnsCertName:nilotherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];[[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];return YES; }

    ViewController中的內(nèi)容

    - (IBAction)login:(id)sender {//用戶名:zlanchun 密碼:123456//異步登陸賬號[[EaseMob sharedInstance].chatManager asyncLoginWithUsername:@"zlanchun" password:@"123456" completion:^(NSDictionary *loginInfo, EMError *error) {if (loginInfo && !error) {//發(fā)送自動登陸狀態(tài)通知[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@YES];} else {NSLog(@"login error: %@",error);}} onQueue:nil]; }- (void)jumpToChatVC {//創(chuàng)建聊天室 對象:zlanchun1EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];[self.navigationController pushViewController:chatController animated:YES]; }

    繼承Demo3.0中的功能

  • 首先導(dǎo)入Demo3.0中如下文件到項目中:

    7
  • 導(dǎo)入class里單聊功能ChatView到項目中

    8
  • 導(dǎo)入完成后的項目目錄

    9
  • 添加頭文件到PCH中。 #ifndef PrefixHeader_pch #define PrefixHeader_pch //頭文件 #import "ChatDemoUIDefine.h" #import "EMAlertView.h" #import "TTGlobalUICommon.h" #import "UIViewController+DismissKeyboard.h" #import "NSString+Valid.h" #import "EaseMob.h" #import "EaseUI.h" #endif /* PrefixHeader_pch */
  • 注釋未引用的文件,刪除重復(fù)引用的文件,添加第三方庫Parse的依賴。
    注釋未引用的文件:

  • 在ViewController.m中應(yīng)用頭文件#import "ChatViewController.h"。然后在跳轉(zhuǎn)方法中,注冊跳轉(zhuǎn)VC,跳轉(zhuǎn)即可。

  • ViewController.m新增部分:

    - (void)jumpToChatVC {//創(chuàng)建聊天室 對象:zlanchun1//EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];//創(chuàng)建基于Demo3.0Class的chatroomChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];[self.navigationController pushViewController:chatController animated:YES]; }

    ChatViewController.m中需要注釋的地方

    #import "ChatViewController.h" //#import "ChatGroupDetailViewController.h" //#import "ChatroomDetailViewController.h" #import "CustomMessageCell.h" //#import "UserProfileViewController.h" //#import "UserProfileManager.h" //#import "ContactListSelectViewController.h" - (void)messageViewController:(EaseMessageViewController *)viewControllerdidSelectAvatarMessageModel:(id<IMessageModel>)messageModel {//UserProfileViewController *userprofile = [[UserProfileViewController alloc] initWithUsername:messageModel.nickname];//[self.navigationController pushViewController:userprofile animated:YES]; } - (id<IMessageModel>)messageViewController:(EaseMessageViewController *)viewControllermodelForMessage:(EMMessage *)message {id<IMessageModel> model = nil;model = [[EaseMessageModel alloc] initWithMessage:message];model.avatarImage = [UIImage imageNamed:@"EaseUIResource.bundle/user"]; // UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:model.nickname]; // if (profileEntity) { // model.avatarURLPath = profileEntity.imageUrl; // }model.failImageName = @"imageDownloadFail";return model; } - (void)showGroupDetailAction {[self.view endEditing:YES]; // if (self.conversation.conversationType == eConversationTypeGroupChat) { // ChatGroupDetailViewController *detailController = [[ChatGroupDetailViewController alloc] initWithGroupId:self.conversation.chatter]; // [self.navigationController pushViewController:detailController animated:YES]; // } // else if (self.conversation.conversationType == eConversationTypeChatRoom) // { // ChatroomDetailViewController *detailController = [[ChatroomDetailViewController alloc] initWithChatroomId:self.conversation.chatter]; // [self.navigationController pushViewController:detailController animated:YES]; // } } - (void)transpondMenuAction:(id)sender { // if (self.menuIndexPath && self.menuIndexPath.row > 0) { // id<IMessageModel> model = [self.dataArray objectAtIndex:self.menuIndexPath.row]; // ContactListSelectViewController *listViewController = [[ContactListSelectViewController alloc] initWithNibName:nil bundle:nil]; // listViewController.messageModel = model; // [listViewController tableViewDidTriggerHeaderRefresh]; // [self.navigationController pushViewController:listViewController animated:YES]; // }self.menuIndexPath = nil; }

    UIImageView+HeadImage.文件中注釋

    /************************************************************* * EaseMob CONFIDENTIAL* __________________* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.** NOTICE: All information contained herein is, and remains* the property of EaseMob Technologies.* Dissemination of this information or reproduction of this material* is strictly forbidden unless prior written permission is obtained* from EaseMob Technologies.*/#import "UIImageView+HeadImage.h" //#import "UserProfileManager.h"@implementation UIImageView (HeadImage)- (void)imageWithUsername:(NSString *)username placeholderImage:(UIImage*)placeholderImage {if (placeholderImage == nil) {placeholderImage = [UIImage imageNamed:@"chatListCellHead"];} // UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:username]; // if (profileEntity) { // [self sd_setImageWithURL:[NSURL URLWithString:profileEntity.imageUrl] placeholderImage:placeholderImage]; // } else { // [self sd_setImageWithURL:nil placeholderImage:placeholderImage]; // }[self sd_setImageWithURL:nil placeholderImage:placeholderImage]; }@end@implementation UILabel (Prase)- (void)setTextWithUsername:(NSString *)username { // UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:username]; // if (profileEntity) { // if (profileEntity.nickname && profileEntity.nickname.length > 0) { // [self setText:profileEntity.nickname]; // [self setNeedsLayout]; // } else { // [self setText:username]; // } // } else { // [self setText:username]; // }[self setText:username]; } @end

    添加parse依賴庫:

    • StoreKit.framework
    • Bolts.framework
    • Parse.framework
    • Accounts.framework
    • Social.framework。
      其中Bolts.framework/Parse.framework在文件夾EaseClass/3rdparty/Parse下。

      10

      11

    刪除重用引用MBProgressHUD庫


    12

    刪除wav.mm文件。


    13

    刪除VoiceConvert文件


    14

    錯誤集合

    • 報錯1:未添加Parse依賴庫引起的clang: error: linker command failed with exit code 1 (use -v to see invocation)錯誤。


      16


      解決辦法:添加parse的依賴庫,一共有5個(環(huán)信小哥告訴我有4個,結(jié)果,添加完4個依賴后,9個錯誤變成4個了。咋辦?還好有Google,查parse依賴關(guān)系,發(fā)現(xiàn)15年7月份依賴增加了一個。)
      剩余的4個錯誤("_OBJC_CLASS_$_SKPayment"):


      17


      看看國外小哥怎么說得(地址)。


      18
    • 報錯2:刪除重復(fù)引用MBProgressHUD庫


      19
    • 報錯3:刪除重復(fù)引用wav.mm文件


      20
    • 報錯4:刪除VoiceConvert文件


      21

    Demo程序見:這里(百度云盤)


    鏈接:http://www.jianshu.com/p/f53be9664f14

    總結(jié)

    以上是生活随笔為你收集整理的环信集成 2---基于环信Demo3.0,实现单聊功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。