{"id":18438157,"url":"https://github.com/easemob/kefu-ios-demo","last_synced_at":"2026-03-10T11:06:36.459Z","repository":{"id":29996854,"uuid":"33544339","full_name":"easemob/kefu-ios-demo","owner":"easemob","description":"demo app for easemob help desk cloud","archived":false,"fork":false,"pushed_at":"2023-04-28T03:01:14.000Z","size":381582,"stargazers_count":53,"open_issues_count":6,"forks_count":30,"subscribers_count":22,"default_branch":"master","last_synced_at":"2026-01-18T12:27:17.474Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/easemob.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,"governance":null}},"created_at":"2015-04-07T13:20:48.000Z","updated_at":"2022-08-31T03:37:55.000Z","dependencies_parsed_at":"2023-07-15T04:02:16.447Z","dependency_job_id":null,"html_url":"https://github.com/easemob/kefu-ios-demo","commit_stats":null,"previous_names":["easemob/helpdeskdemo-ios"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/easemob/kefu-ios-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Fkefu-ios-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Fkefu-ios-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Fkefu-ios-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Fkefu-ios-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easemob","download_url":"https://codeload.github.com/easemob/kefu-ios-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easemob%2Fkefu-ios-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30331657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-11-06T06:18:50.753Z","updated_at":"2026-03-10T11:06:36.434Z","avatar_url":"https://github.com/easemob.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n如需旧版商城demo请跳转:[2.x商城Demo](https://github.com/easemob/helpdeskdemo-ios/tree/master-2.x)\n\n\n\n## 环信客服SDK (iOS 版) ![Build Status](https://travis-ci.org/easemob/kefu-ios-demo.svg?branch=dev-full)\n\n\n## Introduction\n\n\n### 开发工具\n\n\u003e **Xcode**\n\n\n----\n\n## 目录\n\n* [入门指南](#Getting_started_guide)\u003cbr\u003e\n  1.[工程配置](#Guide_build) \u003cbr\u003e\n  2.[集成离线推送](#Guide_APNs) \u003cbr\u003e\n  2.[初始化](#Guide_init)\u003cbr\u003e\n  3.[注册](#Guide_register)\u003cbr\u003e\n  4.[登录](#Guide_login)\u003cbr\u003e\n  5.[退出](#Guide_logout)\u003cbr\u003e\n  6.[会话](#Guide_Chat)\u003cbr\u003e\n  7.[登录状态](#Guide_Login_Status)\u003cbr\u003e\n* [高级选项](#Advanced_Option)\u003cbr\u003e\n\n\n#### \u003cA NAME=\"Guide_build\"\u003e\u003c/A\u003e工程配置\n 请先到[环信官网](http://www.easemob.com/download/cs) 下载\"iOS客服访客端SDK\".\u003cbr\u003e\n 1、在工程中导入 HelpDesk.framework、Hyphenate.framework(包含实时音视频) 和 HelpDeskUI.【注意在导入的时候选择Create groups】\u003cbr\u003e\n 2、选中当前的TARGET,向General → Embedded Binaries 中添加以上两个依赖库. Linked Frameworks and Libraries 中会自动增加. \u003cbr\u003e\n 3、向Build Settings → Linking → Other Linker Flags 中增加-ObjC【注意区分大小写】. \u003cbr\u003e\n 4、在工程info.plist文件中 增加隐私权限 \u003cbr\u003e\n ```\n    Privacy - Photo Library Usage Description 需要访问您的相册\n    Privacy - Microphone Usage Description 需要访问您的麦克风\n    Privacy - Camera Usage Description 需要访问您的摄像机\n ```\n 5、在pch文件或全局.h文件中添加如下代码\u003cbr\u003e\n ```\n   #ifdef __OBJC__\n    #import \u003cHelpDesk/HelpDesk.h\u003e\n   #import \"HelpDeskUI.h\"\n   #endif\n   ```\n#### \u003cA NAME=\"Guide_APNs\"\u003e\u003c/A\u003e离线推送\n```\n    //注册APNs推送\n    [application registerForRemoteNotifications];\n    UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound |   UIUserNotificationTypeAlert;\n    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];\n    [application registerUserNotificationSettings:settings];\n    //您注册了推送功能，iOS 会自动回调以下方法，得到 deviceToken，您需要将 deviceToken 传给 SDK。\n    // 将得到的deviceToken传给SDK\n    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{\n        [[HChatClient sharedClient] bindDeviceToken:deviceToken];\n    }\n\n    // 注册deviceToken失败\n    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{\n        NSLog(@\"error -- %@\",error);\n        //APNS 注册失败，一般是由于使用了通用证书或者是模拟器调试导致，请检查证书并用真机调试。此处是 iOS 系统报的错，如仍不能确定，请从网上查找相关资料。\n    }\n```\n#### \u003cA NAME=\"Guide_init\"\u003e\u003c/A\u003e初始化\n```\n HOptions *option = [[HOptions alloc] init];\n option.appkey = @\"Your appkey\"; //(必填项)\n option.tenantId = @\"Your tenantId\";//(必填项)\n //推送证书名字\n option.apnsCertName = @\"your apnsCerName\";//(集成离线推送必填)\n //Kefu SDK 初始化,初始化失败后将不能使用Kefu SDK\n HError *initError = [[HChatClient sharedClient] initializeSDKWithOptions:option];\n if (initError) { // 初始化错误\n }\n ```\n\n#### \u003cA NAME=\"Guide_register\"\u003e\u003c/A\u003e注册\n\n注册建议在服务端创建，而不要放到APP中，可以在登录自己APP时从返回的结果中获取环信账号再登录环信服务器。\n```\nHError *error = [[HChatClient sharedClient] registerWithUsername:@\"username\" password:@\"password\"];\nerror.code:\nHErrorNetworkUnavailable 网络不可用\nHErrorUserAlreadyExist 用户已存在\nHErrorUserAuthenticationFailed 无开放注册权限（后台管理界面设置[开放|授权]）\nHErrorUserIllegalArgument 用户名非法\n```\n#### \u003cA NAME=\"Guide_login\"\u003e\u003c/A\u003e登录\n由于HChatClient有一个isLoggedInBefore(BOOL)，登录操作前可以先做个判断。\n```\nHChatClient *client = [HChatClient sharedClient];\n    if (client.isLoggedInBefore != YES) {\n        HError *error = [client loginWithUsername:@\"username\" password:@\"password\"];\n        if (!error) { //登录成功\n            HDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@\"IM 服务号\"];\n            [self.navigationController pushViewController:chatVC animated:YES];\n        } else { //登录失败\n            return;\n        }\n    } else { //已经成功登录\n         HDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@\"IM 服务号\"];\n         [self.navigationController pushViewController:chatVC animated:YES];\n    }\n}\n\n```\n\n#### \u003cA NAME=\"Guide_Chat\"\u003e\u003c/A\u003e打开会话页面\n\n```\nHDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@\"IM 服务号\"];\n[self.navigationController pushViewController:chatVC animated:YES];\n```\n#### \u003cA NAME=\"Guide_Login_Status\"\u003e\u003c/A\u003e判断是否已经登录\n\n```\nHChatClient *client = [HChatClient sharedClient];\nif(client.isLoggedInBefore){\n    //已经登录，可以直接进入会话界面\n}else{\n    //未登录，需要登录后，再进入会话界面\n}\n```\n#### \u003cA NAME=\"Guide_logout\"\u003e\u003c/A\u003e登出\n\u003e登出后则无法收到客服发来的消息\n```\n//参数为是否解绑推送的devicetoken\nHError *error = [[HChatClient sharedClient] logout:YES];\nif (error) { //登出出错\n} else {//登出成功\n}\n```\n### \u003cA NAME=\"Advanced_Option\"\u003e\u003c/A\u003e高级选项\n\n#### 添加网络监听,可以显示当前是否连接服务器\n\n```\n//添加网络监控，一般在app初始化的时候添加监控，第二个参数是执行代理方法的队列，默认是主队列\n[[HChatClient sharedClient] addDelegate:self delegateQueue:nil];\n//移除网络监控\n[[HChatClient sharedClient] removeDelegate:self];\n/* 有以下几种情况, 会引起该方法的调用:\n* 1. 登录成功后, 手机无法上网时, 会调用该回调\n* 2. 登录成功后, 网络状态变化时, 会调用该回调*/\n- (void)connectionStateDidChange:(HConnectionState)aConnectionState {\n    switch (aConnectionState) {\n        case HConnectionConnected: {//已连接\n            break;\n        }\n        case HConnectionDisconnected: {//未连接\n            break;\n        }\n        default:\n            break;\n    }\n}\n// 当前登录账号已经被从服务器端删除时会收到该回调\n- (void)userAccountDidRemoveFromServer {\n    \n}\n//当前登录账号在其它设备登录时会接收到此回调\n- (void)userAccountDidLoginFromOtherDevice {\n    \n}\n```\n#### 添加消息监听\n\n```\n//添加消息监控，第二个参数是执行代理方法的队列，默认是主队列\n[[HChatClient sharedClient].chat addDelegate:self delegateQueue:nil];\n//移除消息监控\n[[HChatClient sharedClient].chat removeDelegate:self];\n\n- (void)messagesDidReceive:(NSArray *)aMessages{\n     //收到普通消息,格式:\u003cHMessage *\u003e\n}\n\n- (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages{\n     //收到命令消息,格式:\u003cHMessage *\u003e，命令消息不存数据库，一般用来作为系统通知，例如留言评论更新，\n     //会话被客服接入，被转接，被关闭提醒\n}\n\n- (void)messageStatusDidChange:(HMessage *)aMessage error:(HError *)aError{\n     //消息的状态修改，一般可以用来刷新列表，显示最新的状态\n}\n\n- (void)messageAttachmentStatusDidChange:(HMessage *)aMessage error:(HError *)aError{\n    //发送消息后，会调用，可以在此刷新列表，显示最新的消息\n}\n```\n\n#  其他更多属性请进入[官网文档](http://docs.easemob.com/cs/300visitoraccess/iossdk)查询\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Fkefu-ios-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasemob%2Fkefu-ios-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasemob%2Fkefu-ios-demo/lists"}