{"id":15108892,"url":"https://github.com/leancloud/chatkit-oc","last_synced_at":"2025-09-27T10:30:40.363Z","repository":{"id":56905807,"uuid":"50817818","full_name":"leancloud/ChatKit-OC","owner":"leancloud","description":"此项目已经废弃，以后不再维护。我们推出了基于 Swift SDK 的 Chat Demo。","archived":true,"fork":false,"pushed_at":"2020-06-15T03:42:57.000Z","size":72379,"stargazers_count":2117,"open_issues_count":151,"forks_count":461,"subscribers_count":83,"default_branch":"master","last_synced_at":"2025-01-01T12:03:08.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/leancloud/swift-sdk-demo","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leancloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-01T05:59:03.000Z","updated_at":"2024-12-31T02:27:13.000Z","dependencies_parsed_at":"2022-08-21T03:50:12.400Z","dependency_job_id":null,"html_url":"https://github.com/leancloud/ChatKit-OC","commit_stats":null,"previous_names":[],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FChatKit-OC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FChatKit-OC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FChatKit-OC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leancloud%2FChatKit-OC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leancloud","download_url":"https://codeload.github.com/leancloud/ChatKit-OC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234426049,"owners_count":18830836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T22:42:13.331Z","updated_at":"2025-09-27T10:30:38.297Z","avatar_url":"https://github.com/leancloud.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 注意\n\n此项目已经**废弃**，以后不再维护。我们推出了基于 [Swift SDK](https://github.com/leancloud/swift-sdk) 的 Chat Demo。\n\nChat Demo 位于 [swift-sdk-demo](https://github.com/leancloud/swift-sdk-demo) 项目中。\n\n如果您有任何问题，请联系 support@leancloud.rocks 。\n\n\u003cdetails\u003e\n\u003csummary\u003e以下为原 README 内容\u003c/summary\u003e\n\n# ChatKit 快速入门 · iOS\n\n\u003cp align=\"center\"\u003e\n![enter image description here](https://img.shields.io/badge/pod-v0.8.5-brightgreen.svg)  ![enter image description here](https://img.shields.io/badge/platform-iOS%207.0%2B-ff69b5618733984.svg) \n\u003ca href=\"https://github.com/leancloud/ChatKit-OC/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg?style=flat\"\u003e\u003c/a\u003e[ CocoaPods-Doc](http://cocoapods.org/pods/ChatKit) \n[![git-brag-stats](https://labs.turbo.run/git-brag?user=leancloud\u0026repo=ChatKit-OC\u0026maxn=7)](https://github.com/turbo/git-brag)\n\n\u003c/a\u003e\n\n在使用中有任何问题都可以提 issue，同时也欢迎提 PR。\n\n\n##  导航\n \n 1. [简介](https://github.com/leancloud/ChatKit-OC#简介) \n 2. [获取项目](https://github.com/leancloud/ChatKit-OC#获取项目) \n 2. [集成效果](https://github.com/leancloud/ChatKit-OC#集成效果) \n 3. [项目结构](https://github.com/leancloud/ChatKit-OC#项目结构) \n 4. [使用方法](https://github.com/leancloud/ChatKit-OC#使用方法) \n      1. [CocoaPods 导入](https://github.com/leancloud/ChatKit-OC#cocoapods-导入) \n      2. [快速集成](https://github.com/leancloud/ChatKit-OC#快速集成) \n      3. [最近联系人界面](https://github.com/leancloud/ChatKit-OC#最近联系人界面) \n      4. [由最近联系人进入聊天界面](https://github.com/leancloud/ChatKit-OC#由最近联系人进入聊天界面) \n      4. [聊天界面](https://github.com/leancloud/ChatKit-OC#聊天界面) \n      5. [响应聊天界面的几类操作](https://github.com/leancloud/ChatKit-OC#响应聊天界面的几类操作) \n      5. [手动集成](https://github.com/leancloud/ChatKit-OC#手动集成) \n 8. [常见问题](https://github.com/leancloud/ChatKit-OC#常见问题) \n\n## 简介\n\n[ChatKit](https://github.com/leancloud/ChatKit-OC) 是一个免费且开源的 UI 聊天组件，自带云服务器，自带推送，支持消息漫游，消息永久存储。底层聊天服务基于 [LeanCloud](https://leancloud.cn/?source=T6M35E4H) 的 IM 即时通讯服务，采用 Protobuf 协议进行消息传输。ChatKit 可以帮助开发者快速集成 IM 服务，轻松实现聊天功能，提供完全自由的授权协议，支持二次开发。其最大特点是把聊天常用的一些功能配合 UI 一起提供给开发者。\n\nChatKit 只负责演示聊天的核心逻辑，所以不支持自定义消息（如红包、名片等），并且也不支持 UI 定制。\n\n## 获取项目 \n\n```\ngit clone --depth=1 https://github.com/leancloud/ChatKit-OC\n```\n\n## 集成效果\n\n从大量的使用场景来看，「最近联系人列表」和「聊天界面」这两个页面是开发者最常使用的，同时也是比较难处理的。\n\n最近联系人页面实现的难点在于：\n\n- 要根据最近打开的聊天窗口排序联系人列表；\n- 对每一个最近聊天人／组需要显示最新的一条消息及时间；\n- 需要实时更新未读消息的计数；\n\n而聊天页面的实现难点则在于：\n\n- 消息种类繁多，要有比较好的用户体验，界面以及异步处理方面有大量的开发工作；\n- 音视频消息的录制和发送，需要对系统以及 LeanCloud 实时通信 API 比较熟悉；\n- 推、拉展示本对话中的最新消息，需要对 LeanCloud 实时通信接口比较熟悉；\n\n最近联系人 | 语音消息，根据语音长度调整宽度 | 图片消息，尺寸自适应 \n-------------|-------------|-------------\n![enter image description here](http://i63.tinypic.com/1zxqjns.jpg)|![enter image description here](http://i68.tinypic.com/2rx9sfq.jpg)  | ![enter image description here](http://i64.tinypic.com/aw87wl.jpg) \n\n 地理位置消息| 失败消息本地缓存，可重发 |上传图片，进度条提示 \n -------------|-------------|-------------\n![enter image description here](http://i65.tinypic.com/2vmuaf4.jpg) | ![enter image description here](http://i68.tinypic.com/n6b29v.jpg)| ![enter image description here](http://i66.tinypic.com/orrrxh.jpg)\n\n图片消息支持多图联播，支持多种分享 |文本消息支持图文混排| 文本消息支持双击全屏展示 \n-------------|-------------|------------\n![enter image description here](http://i65.tinypic.com/wmjuvs.jpg) | ![enter image description here](http://i63.tinypic.com/2eoa4j6.jpg) | ![enter image description here](http://i63.tinypic.com/1z1z5ur.jpg)\n\n## 项目结构\n\n```\n├── ChatKit  ＃核心库文件夹\n│   ├── LCChatKit.h  # 这是整个库的入口，也是中枢，相当于”组件化方案“中的 Mediator。\n│   ├── LCChatKit.m\n│   └── Class\n│       ├── Model\n│       ├── Module\n│       │   ├── Base\n│       │   ├── Conversation\n│       │   │   ├── Controller\n│       │   │   ├── Model\n│       │   │   ├── Tool\n│       │   │   └── View\n│       │   └── ConversationList\n│       │       ├── Controller\n│       │       ├── Model\n│       │       └── View\n│       ├── Resources  # 资源文件，如图片、音频等\n│       ├── Tool\n│       │   ├── Service\n│       │   └── Vendor\n│       └── View\n└── ChatKit-OC  # Demo演示\n    ├── ChatKit-OC.xcodeproj\n    └── Example\n        └── LCChatKitExample.h  #这是Demo演示的入口类，这个类中提供了很多胶水函数，可完成初步的集成\n        └── LCChatKitExample.m\n            ├── Model\n            ├── Module\n            │   ├── ContactList\n            │   │   ├── Controller\n            │   │   ├── Tool\n            │   │   └── View\n            │   ├── Login\n            │   │   ├── Controller\n            │   │   ├── Model\n            │   │   └── View\n            │   ├── Main\n            │   │   ├── Controller\n            │   │   └── View\n            │   └── Other\n```\n\n 从上面可以看出，`ChatKit-OC` 项目包分为两个部分：\n\n* `ChatKit` 是库的核心库文件夹。\n* `ChatKit-OC` 为Demo 演示部分，其中 `LCChatKitExample` 这个类提供了很多胶水函数，可完成初步的集成。\n\n\n## 使用方法\n\nChatKit 支持以下两种方式导入到您的项目中：\n\n 1. 通过 CocoaPods 管理依赖\n 2. 手动集成并管理依赖，参考下文的[手动集成](https://github.com/leancloud/ChatKit-OC#手动集成)部分。\n\n这里推荐通过 CocoaPods 管理依赖\n\n\u003e CocoaPods 是目前最流行的 Cocoa 项目库依赖管理工具之一，考虑到便捷与项目的可维护性，我们更推荐您使用 CocoaPods 导入并管理 SDK。\n\n### CocoaPods 导入\n\n 1. CocoaPods 安装\n\n  如果您的机器上已经安装了 CocoaPods，直接进入下一步即可。\n\n  如果您的网络已经翻墙，在终端中运行如下命令直接安装：\n\n  ```shell\n     sudo gem install cocoapods\n  ```\n\n  如果您的网络不能翻墙，可以通过淘宝的 RubyGems 镜像 进行安装。\n\n  在终端依次运行以下命令：\n\n  ```shell\n     gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/\n     sudo gem install cocoapods\n  ```\n\n 2. 查询 CocoaPods 源中的本库\n\n  在终端中运行以下命令：\n\n  ```shell\n     pod search ChatKit\n  ```\n \n   这里注意，这个命令搜索的是本机上的最新版本，并没有联网查询。如果运行以上命令，没有搜到或者搜不到最新版本，您可以运行以下命令，更新一下您本地的 CocoaPods 源列表。\n\n  ```shell\n     pod repo update\n  ```\n \n 3. 使用 CocoaPods 导入\n\n  打开终端，进入到您的工程目录，执行以下命令，会自动生成一个 Podfile 文件。\n\n  ```shell\n     pod init\n  ```\n\n  然后使用 CocoaPods 进行安装。如果尚未安装 CocoaPods，运行以下命令进行安装：\n\n ```shell\n    gem install cocoapods\n ```\n\n  打开 Podfile，在您项目的 target 下加入以下内容。（在此以 v0.8.5 版本为例）\n\n  在文件 `Podfile` 中加入以下内容：\n\n ```shell\n    pod 'ChatKit', '0.8.5'\n ```\n\n  然后在终端中运行以下命令：\n\n ```shell\n    pod install\n ```\n\n  或者这个命令：\n\n ```shell\n    # 禁止升级 CocoaPods 的 spec 仓库，否则会卡在 Analyzing dependencies，非常慢\n    pod update --verbose --no-repo-update\n ```\n\n  如果提示找不到库，则可去掉 `--no-repo-update`。\n\n  完成后，CocoaPods 会在您的工程根目录下生成一个 `.xcworkspace` 文件。您需要通过此文件打开您的工程，而不是之前的 `.xcodeproj`。\n\n然后在需要的地方导入 ChatKit：\n\n  ```Objective-C\n     #import \u003cChatKit/LCChatKit.h\u003e\n  ```\n\n\n**CocoaPods 使用说明**\n\n**指定 SDK 版本**\n\nCocoaPods 中，有几种设置 SDK 版本的方法。如：\n\n`\u003e= 0.8.5` 会根据您本地的 CocoaPods 源列表，导入不低于 0.8.5 版本的 SDK。\n`~\u003e 0.8.5` 会根据您本地的 CocoaPods 源列表，介于 0.7.X~0.8.5 之前版本的 SDK。\n我们建议您锁定版本，便于团队开发。如，指定 0.8.5 版本。\n\n ```shell\npod 'ChatKit', '0.8.5'\n ```\n\n - 升级本地 CocoaPods 源\n\n  `CocoaPods 有一个中心化的源，默认本地会缓存 CocoaPods 源服务器上的所有 SDK 版本。\n\n 如果搜索的时候没有搜到或者搜不到最新版本，可以执行以下命令更新一下本地的缓存。\n\n ```shell\npod repo update\n ```\n \n - 升级工程的Pod版本\n\n 更新您工程目录中 Podfile 指定版本后，在终端中执行以下命令。\n\n ```shell\npod update\n ```\n\n\n - 清除 Cocoapods 本地缓存\n\n 特殊情况下，由于网络或者别的原因，通过 CocoaPods 下载的文件可能会有问题。\n\n 这时候您可以删除 CocoaPods 的缓存(~/Library/Caches/CocoaPods/Pods/Release 目录)，再次导入即可。\n\n - 查看当前使用的 SDK 版本\n\n 您可以在 Podfile.lock 文件中看到您工程中使用的 SDK 版本。\n\n 关于 CocoaPods 的更多内容，您可以参考 [CocoaPods 文档](https://cocoapods.org/)。\n\n\n### 快速集成\n\n使用 ChatKit 有几个关键性的步骤：\n\n 1. 在 `-[AppDelegate application:didFinishLaunchingWithOptions:]` 中调用 `-[LCChatKit setAppId:appKey:]` 来开启 LeanCloud 服务。需要到\n [LeanCloud](https://leancloud.cn/?source=T6M35E4H) 申请一个 AppId 和一个 AppKey，可以在控制台里创建应用，替换 Demo 中的 AppId 和 AppKey。示例代码如下：\n```Objective-C\n - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n    ...\n    // 如果APP是在国外使用，开启北美节点\n    // 必须在 APPID 初始化之前调用，否则走的是中国节点。\n    // [AVOSCloud setServiceRegion:AVServiceRegionUS];\n    [LCChatKit  setAppId:LCCKAPPID  appKey:LCCKAPPKEY];\n    // 启用未读消息\n    [AVIMClient  setUnreadNotificationEnabled:true];\n\n   //添加输入框底部插件，如需更换图标标题，可子类化，然后调用 `+registerSubclass`\n   [LCCKInputViewPluginTakePhoto  registerSubclass];\n   [LCCKInputViewPluginPickImage  registerSubclass];\n   [LCCKInputViewPluginLocation  registerSubclass];\n     ...\n }\n```\n 2. 调用 `-[LCChatKit sharedInstance]` 来初始化一个单例对象。为了让这个库更易入手，避免引入过多公开的类和概念，我们采用了设计模式中的「门面模式」，将你在使用 ChatKit 库时所需要用到的所有方法都放在了 `LCChatKit` 这一个类中。它是一个 Mediator，是整个库的入口。如果不作出特殊说明，下面所说的「调用 API」，调用方都是 `-[LCChatKit sharedInstance]` 。示意图如下：\n\n ![](http://ww2.sinaimg.cn/large/801b780ajw1f88fhsglsxj20dn08oq3d.jpg)\n\n 3. 实现 `-[[LCChatKit sharedInstance] setFetchProfilesBlock:]`，设置用户体系，里面要实现如何根据 userId 获取到一个 User 对象的逻辑。ChatKit 会在需要用到 User 信息时调用你设置的这个逻辑。更具体的设置方法请参考： [《ChatKit 自定义业务-设置单聊用户的头像和昵称》](https://github.com/leancloud/ChatKit-OC/blob/master/ChatKit%20自定义业务.md#设置单聊用户的头像和昵称) 。`LCCKUserSystemService.h` 文件中给出了例子，演示了如何集成 LeanCloud 原生的用户系统 `AVUser`:\n```Objective-C\n [[LCChatKit  sharedInstance] setFetchProfilesBlock:^(NSArray\u003cNSString *\u003e *userIds,\n LCCKFetchProfilesCompletionHandler completionHandler) {\n if (userIds.count == 0) {\n NSInteger code = 0;\n NSString *errorReasonText = @\"User ids is nil\";\n NSDictionary *errorInfo = @{\n @\"code\":@(code),\n NSLocalizedDescriptionKey : errorReasonText,\n };\n  NSError *error = [NSError  errorWithDomain:NSStringFromClass([self  class])\n code:code\n userInfo:errorInfo];\n !completionHandler ?: completionHandler(nil, error);\n return;\n }\n  NSMutableArray *users = [NSMutableArray  arrayWithCapacity:userIds.count];\n [userIds enumerateObjectsUsingBlock:^(NSString *_Nonnull clientId, NSUInteger idx,\n BOOL *_Nonnull stop) {\n NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"peerId like %@\", clientId];\n  //这里的LCCKContactProfiles，LCCKProfileKeyPeerId都为事先的宏定义，\n NSArray *searchedUsers = [LCCKContactProfiles filteredArrayUsingPredicate:predicate];\n if (searchedUsers.count \u003e 0) {\n NSDictionary *user = searchedUsers[0];\n NSURL *avatarURL = [NSURL URLWithString:user[LCCKProfileKeyAvatarURL]];\n LCCKUser *user_ = [LCCKUser userWithUserId:user[LCCKProfileKeyPeerId]\n name:user[LCCKProfileKeyName]\n avatarURL:avatarURL\n clientId:clientId];\n [users addObject:user_];\n } else {\n LCCKUser *user_ = [LCCKUser userWithClientId:clientId];\n [users addObject:user_];\n }\n }];\n !completionHandler ?: completionHandler([users copy], nil);\n }];\n```\n\n 4. 如果你实现了 `-[[LCChatKit sharedInstance] setGenerateSignatureBlock:]` 方法，那么 ChatKit 会自动为以下行为添加签名：`open`（开启聊天）、`start`（创建对话）、`kick`（踢人）、`invite`（邀请）。反之不会。\n 5. 调用 `-[[LCChatKit sharedInstance] openWithClientId:callback:]` 开启 LeanCloud 的 IM 服务 LeanMessage，开始聊天。请确保在 open 操作之前已经实现 `-[[LCChatKit sharedInstance] setFetchProfilesBlock:]`，否则 ChatKit 将抛出异常进行提示。\n 6. 调用 `-[[LCChatKit sharedInstance] closeWithCallback:]` 关闭 LeanCloud 的 IM 服务，结束聊天。\n\n### 最近联系人界面\n\n主流的社交聊天软件，例如微信和 QQ 都会把最近联系人界面作为登录后的首页，可见其重要性。因此我们在 ChatKit 也提供了对话列表 `LCIMConversationListController` 页面，初始化方法非常简单：\n\n```Objective-C\nLCCKConversationListViewController *firstViewController = [[LCCKConversationListViewController alloc] init];\n```\n\n因为最近联系人的所有信息都由 ChatKit 内部维护，不需要传入额外数据，所以直接展示这个 ViewController 即可。最近联系人界面的数据，依赖于本地数据库。这些数据会在聊天过程中自动进行更新，你无需进行繁琐的数据库操作。\n\n### 聊天界面\n\n\u003cdiv class=\"callout callout-info\"\u003eChatKit 中的对话是一个 `AVIMConversation` 对象， LeanMessage\n用它来管理对话成员，发送消息，不区分群聊、单聊。Demo 中采用了判断对话人数的方式来区分群聊、单聊。\u003c/div\u003e\n\n聊天界面有两种初始化方式：\n\n```Objective-C\n// 用于单聊，默认会创建一个只包含两个成员的 unique 对话(如果已经存在则直接进入，不会重复创建)\nLCCKConversationViewController *conversationViewController = [[LCCKConversationViewController alloc] initWithPeerId:peerId];\n```\n\n```Objective-C\n// 单聊或群聊，用于已经获取到一个对话基本信息的场合。\nLCCKConversationViewController *conversationViewController = [[LCCKConversationViewController alloc] initWithConversationId:conversationId];\n```\n\n这里注意，通过 `peerId` 初始化，内部实现时，如果没有一个 unique 对话刚好包含这两个成员，则会先创建一个 unique 对话，所以调用该方法时可能会导致 _Conversation 表中自动增加一条记录。同理，通过 `conversationId` 初始化群聊，内部实现时，如果不是对话成员会先把当前用户加入对话，并开启群聊。\n\n#### 由最近联系人进入聊天界面\n\n按照上面的步骤，我们可以非常方便地打开最近联系人页面。但是我们会发现，点击其中的某个联系人／聊天群组，我们并不能直接进入聊天界面。要做到这一点，我们需要给 LCChatKit 设置上事件响应函数，示例代码如下：\n\n```objective-c\n[[LCChatKit sharedInstance] setDidSelectConversationsListCellBlock:^(NSIndexPath *indexPath, AVIMConversation *conversation, LCCKConversationListViewController *controller) {\n    NSLog(@\"conversation selected\");\n    LCCKConversationViewController *conversationVC = [[LCCKConversationViewController alloc] initWithConversationId:conversation.conversationId];\n    [controller.navigationController pushViewController:conversationVC animated:YES];\n}];\n```\n\n对于联系人列表页面，可以使用 `[LCChatKit sharedInstance]` 来调用如下四种操作接口：\n\n\n```objective-c\n/*!\n *  选中某个对话后的回调 (比较常见的需求)\n *  @param conversation 被选中的对话\n */\ntypedef void(^LCCKConversationsListDidSelectItemBlock)(NSIndexPath *indexPath, AVIMConversation *conversation, LCCKConversationListViewController *controller);\n/*!\n *  设置选中某个对话后的回调\n */\n- (void)setDidSelectConversationsListCellBlock:(LCCKConversationsListDidSelectItemBlock)didSelectItemBlock;\n\n/*!\n *  删除某个对话后的回调 (一般不需要做处理)\n *  @param conversation 被选中的对话\n */\ntypedef void(^LCCKConversationsListDidDeleteItemBlock)(NSIndexPath *indexPath, AVIMConversation *conversation, LCCKConversationListViewController *controller);\n/*!\n *  设置删除某个对话后的回调\n */\n- (void)setDidDeleteConversationsListCellBlock:(LCCKConversationsListDidDeleteItemBlock)didDeleteItemBlock;\n\n/*!\n *  对话左滑菜单设置block (最近联系人页面有复杂的手势操作时，可以通过这里扩展实现)\n *  @return  需要显示的菜单数组\n *  @param conversation, 对话\n *  @param editActions, 默认的菜单数组，成员为 UITableViewRowAction 类型\n */\ntypedef NSArray *(^LCCKConversationEditActionsBlock)(NSIndexPath *indexPath, NSArray\u003cUITableViewRowAction *\u003e *editActions, AVIMConversation *conversation, LCCKConversationListViewController *controller);\n/*!\n *  可以通过这个block设置对话列表中每个对话的左滑菜单，这个是同步调用的，需要尽快返回，否则会卡住UI\n */\n- (void)setConversationEditActionBlock:(LCCKConversationEditActionsBlock)conversationEditActionBlock;\n```\n\n### 响应聊天界面的几类操作\n\n由于有了 ChatKit 的帮助，聊天界面的初始化和展示非常简单，但是这里面交互上还有很多地方需要自定义扩展。\n\n- 内部异常对话无法创建\n\n如果通过 peerId 打开对话，或者通过 conversationId 打开对话时，网络出现问题或 传入参数有误，那么对话根本无法进行，这时候我们可以通过给 LCCKConversationViewController 设定 conversationHandler 进行处理。示例代码如下：\n\n```objective-c\n [[LCChatKit sharedInstance] setFetchConversationHandler:^(\n                                                              AVIMConversation *conversation,\n                                                              LCCKConversationViewController *aConversationController) {\n    if (!conversation) {\n        // 显示错误提示信息\n        [conversationController alert:@\"failed to create/load conversation.\"];\n    } else {\n        // 正常处理\n    }\n}];\n```\n\n这里注意这个 `-setFetchConversationHandler:` 方法无需每次创建 `LCCKConversationViewController` 对象都要设置一遍，只需要设置一次，之后每次创建 `LCCKConversationViewController` 对象都会复用该设置。\n\n- 对话详情页展示\n\n在 QQ／微信之类的聊天应用中，聊天界面右上角会提供一个显示对话详细信息的按钮，点击可以打开对话详情页面，在那里可以进行改名、拉人、踢人、静音等操作。LCCKConversationViewController 中通过调用以下 API 也支持这一功能：\n\n```objective-c\ntypedef void(^LCCKBarButtonItemActionBlock)(void);\n\ntypedef NS_ENUM(NSInteger, LCCKBarButtonItemStyle) {\n    LCCKBarButtonItemStyleSetting = 0,\n    LCCKBarButtonItemStyleMore,\n    LCCKBarButtonItemStyleAdd,\n    LCCKBarButtonItemStyleAddFriends,\n    LCCKBarButtonItemStyleShare,\n    LCCKBarButtonItemStyleSingleProfile,\n    LCCKBarButtonItemStyleGroupProfile,\n};\n\n- (void)configureBarButtonItemStyle:(LCCKBarButtonItemStyle)style action:(LCCKBarButtonItemActionBlock)action;\n```\n\n示例代码如下：\n\n```objective-c\n[aConversationController configureBarButtonItemStyle:LCCKBarButtonItemStyleGroupProfile\n                                                          action:^(UIBarButtonItem *sender, UIEvent *event) {\n    ConversationDetailViewController *detailVC = [[ConversationDetailViewController alloc] init];// 自己实现的对话详情页\n    detailVC.conversation = conversation;\n    [conversationController.navigationController pushViewController:detailVC animated:YES];\n}];\n```\n\n### 手动集成\n\n如果你不想使用 CocoaPods 进行集成，也可以选择使用源码集成。步骤如下：\n\n第一步：\n\n将 [项目结构](https://github.com/leancloud/ChatKit-OC#项目结构) 中提到的 ChatKit 这个「核心库文件夹」拖拽到项目中。\n\n第二步：\n\n添加 ChatKit 依赖的第三方库以及对应版本：\n\n- [AVOSCloud](https://github.com/leancloud/objc-sdk) v3.6.1\n- [AVOSCloudIM](https://github.com/leancloud/objc-sdk) v3.6.1\n- [MJRefresh](https://github.com/CoderMJLee/MJRefresh) 3.1.9\n- [Masonry](https://github.com/SnapKit/Masonry) v1.0.1 \n- [SDWebImage](https://github.com/rs/SDWebImage) v3.8.0\n- [FMDB](https://github.com/ccgus/fmdb) 2.6.2 \n- [UITableView+FDTemplateLayoutCell](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell) 1.5.beta\n\n具体以  [这里](https://github.com/leancloud/ChatKit-OC/blob/master/ChatKit.podspec) 为准。\n\n## 常见问题\n\n**ChatKit 组件收费么？**\u003cbr/\u003e\nChatKit 是完全开源并且免费给开发者使用，使用聊天所产生的费用以 [这里](https://leancloud.cn/pricing.html) 为准。\n\n**接入 ChatKit 有什么好处？**\u003cbr/\u003e\n它可以减轻应用或者新功能研发初期的调研成本，直接引入使用即可。ChatKit 从底层到 UI 提供了一整套的聊天解决方案。\n\n**如何兼容 iOS7 ？**\u003cbr/\u003e\n因为ChatKit中使用了 iOS8 的一个控件：UITableViewRowAction ，所以想要兼容 iOS7 就需要在你的 App 中添加一个 Lib：\n\n ```Objective-C\npod \"CYLTableViewRowAction\", \"1.0.0\"\n ```\n\nDemo 中也是通过这个方式来兼容iOS7的。\n\n如果不使用 Pod，你可以直接下载 [CYLTableViewRowAction](https://github.com/ChenYilong/CYLTableViewRowAction) 将里面的文件夹拖拽到项目中就可以了，不兼容 iOS7 的问题就解决了。\n\n**为什么收不到推送消息 ？**\u003cbr/\u003e\n问题描述：推送的证书已经配置好，在控制台里测试推送，手机也能接收到，但是另一个好友发送的消息就是接收不到。\n\n这种情况，请先参考 [《iOS 消息推送开发指南》](https://leancloud.cn/docs/ios_push_guide.html) ，如果设置方法正确，再检查下这里是否进行了正确的设置：\n\n比如可以这样设置：\n\n ```Objective-C\n{\"alert\":\"您有新的消息\",\"badge\":\"Increment\"}\n ```\n\n![](http://ww2.sinaimg.cn/large/7853084cjw1f7y0ltdaprj20r20fiacf.jpg)\n\n如果想获取推送的消息内容可以参考  [《 iOS 消息推送 点击app图标 app icon如何获取推送信息 leanCloud 点击app图标 获得推送消息》]( http://blog.csdn.net/zain_/article/details/50440096\n ) \n\n在使用中有任何问题都可以到[我们的官方论坛](https://forum.leancloud.cn/c/jing-xuan-faq)提问题，会有专业工程师回复，平均响应时间在24小时内。\n\n\u003c/details\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fchatkit-oc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleancloud%2Fchatkit-oc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleancloud%2Fchatkit-oc/lists"}