美文网首页
环信iOS端IM、移动客服--集成介绍与使用实践

环信iOS端IM、移动客服--集成介绍与使用实践

作者: R_yan | 来源:发表于2017-01-05 20:18 被阅读879次

    前言

    本文属个人笔记,不做详解,仅供参考
    业务需求:1.即时聊天(单聊、群聊); 2.支持移动客服功能(机器人自动应答、超时自动结束会话、发送自定义产品到客户、评价等)

    使用

    • 注册成为环信开发者,集成即时聊天和移动客服账户是需要分开注册的(如果需要集成移动客服,必须先集成即时通讯)。
    • 应用创建成功获得以下信息,需要注意的是:推送证书(上传开发、生产推送证书)、AppKey(初始化SDK需要)、Client Id和Client Secret在移动客服“添加APP关联”会用到。


      应用创建成功.png
    • 通过Cocoapods下载SDK--- pod 'Hyphenate_CN’ ,下载环信SDKdemo后将EaseUI文件夹拷贝到项目中(之所以选择手动添加进项目是因为聊天页的UI多以自定义为主,手动添加方便测试,当然也可以pod导入)
    • 由于SDK代码是OC,如果项目使用Swift开发,还需要配置下工程:
      1.创建pch文件导入#import <UIKit/UIKit.h>
      2.创建一个.h文件作为桥接文件,导入#import <Foundation/Foundation.h> #import "EMSDKFull.h" #import "EaseUI.h"
      3.TARGETS->Build Settings->搜索"prefix",添加pch文件到"Prefix Header";
      4.搜索"bridge",添加桥接文件到"Objective-C Bridging Header";
      5.搜索"bitcode"为NO
    • 进入AppDelegate中初始化SDK
    //环信初始化
    let options = EMOptions.init(appkey:"1113161221178022#hxdemo")
    options.apnsCertName = "developer"
    let error = EMClient.sharedClient().initializeSDKWithOptions(options)
    if error == nil {
       print("初始化成功")
    }else{
       print("初始化失败")
    }
    
    • 创建控制器继承 "EaseMessageViewController"
    
        override init!(conversationChatter: String!, conversationType: EMConversationType) {
            super.init(conversationChatter: conversationChatter, conversationType: conversationType)
        }
        
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
            super.init(nibName: nil, bundle: nil)
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            self.navigationItem.title = "聊天"
            self.delegate = self
            self.dataSource = self
        }
        
        // 点击头像回调
        func messageViewController(viewController: EaseMessageViewController!, didSelectAvatarMessageModel messageModel: IMessageModel!) {
            print("messageModel:\(messageModel.nickname)    message:\(messageModel.text)")
        }
        // 是否允许长按
        func messageViewController(viewController: EaseMessageViewController!, canLongPressRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
            return true
        }
    }
    
    • 到了这一步,即时通信的功能基本实现。先看下demo效果:
    demo演示.gif

    演示账户:user001、user002、user003、user004、user005,密码都是:123
    (user001为客服号,因为环信客服只免费体验2周,我的账户到期了,可能demo内的移动客服功能展示不全。各位自己注册体验即可)

    • 下面我们接入移动客服业务:
      1、登录环信客服(登录成功后右上角点击切换到"管理员模式");
      2、点击左边目录的“渠道管理”->"手机APP";
      3、点击右上角“添加APP关联”->"去关联IM账号"


      添加APP关联.png

      4、AppKey、ClientId、ClientSecret都在之前创建应用的时候获得了。IM服务号就是你要设置的客服的账号,IM Password为账号密码
      5、配置客服设定:左侧菜单"设置",这里可以设置客服欢迎语、问候语、结束语以及工作时间设置等
      6、点击右上角切换到”客服模式“可查看会话情况


      客服自动回复.png
    客服超时.png

    最后

    至此,需求基本实现。如有问题可下载demo或者私信。

    相关文章

      网友评论

          本文标题:环信iOS端IM、移动客服--集成介绍与使用实践

          本文链接:https://www.haomeiwen.com/subject/gmrfvttx.html