Code Monkey home page Code Monkey logo

kefu-ios-demo's Introduction

如需旧版商城demo请跳转:2.x商城Demo

环信客服SDK (iOS 版) Build Status

Introduction

开发工具

Xcode


目录

工程配置

请先到环信官网 下载"iOS客服访客端SDK".
1、在工程中导入 HelpDesk.framework、Hyphenate.framework(包含实时音视频) 和 HelpDeskUI.【注意在导入的时候选择Create groups】
2、选中当前的TARGET,向General → Embedded Binaries 中添加以上两个依赖库. Linked Frameworks and Libraries 中会自动增加.
3、向Build Settings → Linking → Other Linker Flags 中增加-ObjC【注意区分大小写】.
4、在工程info.plist文件中 增加隐私权限

   Privacy - Photo Library Usage Description 需要访问您的相册
   Privacy - Microphone Usage Description 需要访问您的麦克风
   Privacy - Camera Usage Description 需要访问您的摄像机

5、在pch文件或全局.h文件中添加如下代码

  #ifdef __OBJC__
   #import <HelpDesk/HelpDesk.h>
  #import "HelpDeskUI.h"
  #endif

离线推送

    //注册APNs推送
    [application registerForRemoteNotifications];
    UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound |   UIUserNotificationTypeAlert;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
    [application registerUserNotificationSettings:settings];
    //您注册了推送功能,iOS 会自动回调以下方法,得到 deviceToken,您需要将 deviceToken 传给 SDK。
    // 将得到的deviceToken传给SDK
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
        [[HChatClient sharedClient] bindDeviceToken:deviceToken];
    }

    // 注册deviceToken失败
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
        NSLog(@"error -- %@",error);
        //APNS 注册失败,一般是由于使用了通用证书或者是模拟器调试导致,请检查证书并用真机调试。此处是 iOS 系统报的错,如仍不能确定,请从网上查找相关资料。
    }

初始化

 HOptions *option = [[HOptions alloc] init];
 option.appkey = @"Your appkey"; //(必填项)
 option.tenantId = @"Your tenantId";//(必填项)
 //推送证书名字
 option.apnsCertName = @"your apnsCerName";//(集成离线推送必填)
 //Kefu SDK 初始化,初始化失败后将不能使用Kefu SDK
 HError *initError = [[HChatClient sharedClient] initializeSDKWithOptions:option];
 if (initError) { // 初始化错误
 }

注册

注册建议在服务端创建,而不要放到APP中,可以在登录自己APP时从返回的结果中获取环信账号再登录环信服务器。

HError *error = [[HChatClient sharedClient] registerWithUsername:@"username" password:@"password"];
error.code:
HErrorNetworkUnavailable 网络不可用
HErrorUserAlreadyExist 用户已存在
HErrorUserAuthenticationFailed 无开放注册权限(后台管理界面设置[开放|授权])
HErrorUserIllegalArgument 用户名非法

登录

由于HChatClient有一个isLoggedInBefore(BOOL),登录操作前可以先做个判断。

HChatClient *client = [HChatClient sharedClient];
    if (client.isLoggedInBefore != YES) {
        HError *error = [client loginWithUsername:@"username" password:@"password"];
        if (!error) { //登录成功
            HDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@"IM 服务号"];
            [self.navigationController pushViewController:chatVC animated:YES];
        } else { //登录失败
            return;
        }
    } else { //已经成功登录
         HDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@"IM 服务号"];
         [self.navigationController pushViewController:chatVC animated:YES];
    }
}

打开会话页面

HDMessageViewController *chatVC = [[HDMessageViewController alloc] initWithConversationChatter:@"IM 服务号"];
[self.navigationController pushViewController:chatVC animated:YES];

判断是否已经登录

HChatClient *client = [HChatClient sharedClient];
if(client.isLoggedInBefore){
    //已经登录,可以直接进入会话界面
}else{
    //未登录,需要登录后,再进入会话界面
}

登出

登出后则无法收到客服发来的消息

//参数为是否解绑推送的devicetoken
HError *error = [[HChatClient sharedClient] logout:YES];
if (error) { //登出出错
} else {//登出成功
}

高级选项

添加网络监听,可以显示当前是否连接服务器

//添加网络监控,一般在app初始化的时候添加监控,第二个参数是执行代理方法的队列,默认是主队列
[[HChatClient sharedClient] addDelegate:self delegateQueue:nil];
//移除网络监控
[[HChatClient sharedClient] removeDelegate:self];
/* 有以下几种情况, 会引起该方法的调用:
* 1. 登录成功后, 手机无法上网时, 会调用该回调
* 2. 登录成功后, 网络状态变化时, 会调用该回调*/
- (void)connectionStateDidChange:(HConnectionState)aConnectionState {
    switch (aConnectionState) {
        case HConnectionConnected: {//已连接
            break;
        }
        case HConnectionDisconnected: {//未连接
            break;
        }
        default:
            break;
    }
}
// 当前登录账号已经被从服务器端删除时会收到该回调
- (void)userAccountDidRemoveFromServer {
    
}
//当前登录账号在其它设备登录时会接收到此回调
- (void)userAccountDidLoginFromOtherDevice {
    
}

添加消息监听

//添加消息监控,第二个参数是执行代理方法的队列,默认是主队列
[[HChatClient sharedClient].chat addDelegate:self delegateQueue:nil];
//移除消息监控
[[HChatClient sharedClient].chat removeDelegate:self];

- (void)messagesDidReceive:(NSArray *)aMessages{
     //收到普通消息,格式:<HMessage *>
}

- (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages{
     //收到命令消息,格式:<HMessage *>,命令消息不存数据库,一般用来作为系统通知,例如留言评论更新,
     //会话被客服接入,被转接,被关闭提醒
}

- (void)messageStatusDidChange:(HMessage *)aMessage error:(HError *)aError{
     //消息的状态修改,一般可以用来刷新列表,显示最新的状态
}

- (void)messageAttachmentStatusDidChange:(HMessage *)aMessage error:(HError *)aError{
    //发送消息后,会调用,可以在此刷新列表,显示最新的消息
}

其他更多属性请进入官网文档查询

kefu-ios-demo's People

Contributors

dujiepeng avatar fanapple avatar fudonghai avatar jma01 avatar liyuzhao avatar lizilong1989 avatar wyuzhang avatar xieyajie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kefu-ios-demo's Issues

Xcode 8.3 报错

系统版本 10.12.4 (16E195)。helpdeskfull_sdk 文件找不到。。。
fb693769-d063-4c10-8b94-ff7f24d8ea54

数据库报错

为什么我切换用户后,进入会话页会出现
Unknown error calling sqlite3_step (10: disk I/O error) rs
2017-04-17 20:44:58.021663 --[1370:301026] Unknown error calling sqlite3_step (10: disk I/O error) eu
2017-04-17 20:44:58.021843 --[1370:301026] DB Query: INSERT INTO conversations (conversationid,unreadcount) VALUES (?,?)
2017-04-17 20:44:58.021985 --[1370:301026] Unknown error finalizing or resetting statement (10: disk I/O error)
2017-04-17 20:44:58.022145 --[1370:301026] DB Query: INSERT INTO conversations (conversationid,unreadcount) VALUES (?,?)
2017-04-17 20:44:58.023424 --[1370:301026] Unknown error calling sqlite3_step (10: disk I/O error) eu
2017-04-17 20:44:58.023677 --[1370:301026] DB Query: UPDATE conversations SET unreadcount = ?
2017-04-17 20:44:58.023817 --[1370:301026] Unknown error finalizing or resetting statement (10: disk I/O error)
2017-04-17 20:44:58.024464 --[1370:301026] DB Query: UPDATE conversations SET unreadcount = ?
2017-04-17 20:44:58.076026 --[1370:301026] Unknown error calling sqlite3_step (10: disk I/O error) rs

Something looks wrong in EMIMHelper.m

On line 80 of file EMIMHelper.m, the code below seems to be opposite.

 [userDefaults setObject:@"username" forKey:_username];
 [userDefaults setObject:@"password" forKey:_password];

should this be the code below?

 [userDefaults setObject:@_username forKey:"username"];
 [userDefaults setObject:@_password forKey:"password"];

编译不过

Xcode Version 7.2 (7C68) 编译不过,少文件。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.