Skip to content

QIMSDK 二次开发

haibin li edited this page Dec 19, 2019 · 12 revisions

QIMSDK二次开发示例(Demo见 IMSDK-iOS IMSDKPrivateFork 分支

  1. Fork各个组件
  2. 下载各个组件库代码到你的项目根目录
    git clone https://github.com/qunarcorp/libqimcommon-ios
    git clone https://github.com/qunarcorp/libqimcommoncategories-ios.git
    git clone https://github.com/qunarcorp/libqimdatabase-ios.git
    git clone https://github.com/qunarcorp/libqimgeneralmodule-ios.git
    git clone https://github.com/qunarcorp/libqimkitvendor-ios.git
    git clone https://github.com/qunarcorp/libqimopenssl-ios.git
    git clone https://github.com/qunarcorp/libqimuikit-ios.git
    git clone https://github.com/qunarcorp/QIMReactNativeLibrary.git
    
  3. 修改Podfile文件
     $debug = ENV['debug']
     if $debug
       puts '本地debug方式'
       pod 'QIMUIKit', path: './libqimuikit-ios'
       pod 'QIMGeneralModule', path: './libqimgeneralmodule-ios'
       pod 'QIMCommon', path: './libQIMCommon-iOS'
       pod 'QIMKitVendor', path: './libqimkitvendor-ios'
       pod 'QIMDataBase', path: './libqimdatabase-ios'
       pod 'QIMCommonCategories', path: './libqimcommoncategories-ios'
       pod 'QIMReactNativeLibrary', path: './QIMReactNativeLibrary'
    
     else
       puts '线上release方式'
       pod 'QIMUIKit', '~> 4.0'
     end
    
  4. 在项目根目录执行debug=1 pod install
  5. 为了防止宿主项目git size变的过大,可以在.gitignore中过滤各个组件库
  6. 修改你需要修改的代码,然后提交到你fork的组件库仓库

注意事项

  1. 引入QIMCommon库的公共头文件

    #import "QIMKitPublicHeader.h"

    QIMCommon库为了保险起见,最好都调用[QIMKit sharedInstance], QIMManager类中的方法不能直接调用,随时可能会有改动。

我怎么新加一种消息类型呢???都需要改哪些内容

新加消息消息类型只需要新加一个枚举值!!!(各客户端需保持一致)

(iOS项目中QIMCommonEnum.h头文件中QIMMessageType枚举,切记不能和枚举中的其他值冲突。)

服务器零改动!!!

服务器零改动!!!

服务器零改动!!!

如何发送自定义消息?

  1. 只需在QIMChatVc.m/QIMGroupChatVC.m中定义一个方法,先创建一个QIMMessageModel对象,然后调用发送消息API

例如发送视频文件消息:

QIMMessageModel *msg = [[QIMKit sharedInstance] createMessageWithMsg:@"jsonVideo" extenddInfo:@"jsonVideo" userId:self.chatId userType:self.chatType msgType:QIMMessageType_SmallVideo]; //此处改成自己定义的消息枚举值

[[QIMKit sharedInstance] sendMessage:msg ToUserId:self.chatId];

我怎么对新增的消息类型画cell呢???

  1. 新建Cell类:QIMMessageTypeNewCustomMessageCell,继承自QIMMsgBaloonBaseCell类 (可参照项目中已有的QIMVideoMsgCell.m)

  2. 实现对应的父类方法

    //根据业务需要计算cell的高度
    + (CGFloat)getCellHeightWithMessage:(QIMMessageModel *)message chatType:(ChatType)chatType {
       return 0;
    }
    
    - (void)refreshUI {
      /*
      1. 在这里可以获取self.message
      2. 解析self.message中的字段来画ui
        说明:
       self.message.message == 发送消息时候 MsgModel中的WithMsg:参数
       self.message.extenddInfo == 发送消息时候 MsgModel中的extenddInfo:参数
    
      特别主意:
      我们当前在新版本客户端新增了一种msgType=111111,名叫小程序卡片消息。老版本客户端肯定不认识这种消息类型。那么新版本客户端在发送消息的时候,塞给MsgModel的message属性为"[你收到了一个小程序,请在手机上查看]",ExtendInfo才是真正的消息内容。 这样老版本客户端遇到这种不认识的消息,会默认展示self.message.message中的内容。
      结论:messageModel.message属性用作给老版本客户端的提示,messageModel.extendInfo用作新版本展示时候真正解析的。(各个客户端都是这个逻辑)
      */
    }
    
  3. 注册消息Cell类 打开QTalk.m类,文件最下面新增

    //根据消息类型枚举值,注册不同的消息cell类名,运行时动态根据类名动态查找,可减少硬编码

    [[QIMKit sharedInstance] registerMsgCellClassName:@"QIMMessageTypeNewCustomMessageCell"ForMessageType:QIMMessageTypeNewCustomMessageType];
    

    //设置一下自定义消息在消息列表展示的内容。例如:语音消息在会话内展示语音气泡,在消息列表页面展示的是"[语音]"

    [[QIMKit sharedInstance] setMsgShowText:@"我的自定义消息" ForMessageType:QIMMessageTypeNewCustomMessageType];
    
  4. 我自定义的Cell不想要长按选择菜单,怎么搞?

    实现showMenuActionTypeList()方法

     - (NSArray *)showMenuActionTypeList {
        return @[];
     }
    

我怎么修改项目中的字体和图标呢???

  1. 我们项目中的字体使用的都是系统字体

  2. 图标一部分图标使用的png,一部分图标使用的iconFont

  • 新增png图标
    1. 找到项目中QIMUIKit.bundle
    2. 新增xxx@2x.png图标 (由于App Size问题,我们目前只支持@2x图,所以图片文件名必须以@2x.png结尾
    3. 在代码中使用[UIImage qim_imageNamedFromQIMUIKitBundle:@"xxx"]获取UIImage对象
  • 替换iconFont
    1. 找到QTalk-QChat.ttf文件,
    2. 再Fonts目录下拷贝你的ttf文件(例:mycustom.ttf)。
    3. 打开项目中的info.plist,新加Fonts provided by application key,Type为Array,添加一个item:mycustom.ttf
    4. 打开类QTalk.m,修改initConfiguration方法, [QIMIconFont setFontName:@"mycustom"];
    5. 打开头文件QIMUIFontConfig.h, 修改里面的define宏定义。

我怎么修改群名片/个人名片页面UI

  1. 下载qimrn工程 https://github.com/qunarcorp/qimrn

  2. 依照qimrn工程的README进行调试以及打包