使用 Swift编写的 iOS 实时客服小部件。
此小部件不仅是一个电子邮件类型的支持小部件。TTLiveAgentWidget 将知识库文章展示给用户,这样他们可以快速找到解决问题的方案。它与任何 API 版本为 1 的实时客服服务器一起工作。
为了更好的性能和安全性,我们建议使用代理服务器。请参阅我们的代理服务器 TTLiveAgentWidget-ProxyServer。
手动将 Pod
文件夹的内容拖放到您的项目中。
或通过 CocoaPods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'TTLiveAgentWidget'
首先导入小部件。
// Swift
import TTLiveAgentWidget
// Objective-C
#import "TTLiveAgentWidget-Swift.h"
在使用小部件之前,您需要对其进行配置。至少,您需要设置 API URL、包含知识库文章的实时客服文件夹 ID、知识库主题和客服电子邮件。基本的配置如下:
let liveAgentWidget = TTLiveAgentWidget.getInstance()
liveAgentWidget.apiURL = "http://liveagent.server"
liveAgentWidget.apiKey = "123456"
liveAgentWidget.apiFolderId = 10
liveAgentWidget.supportEmail = "[email protected]"
// Set topics
supportWidget.topics = [
SupportTopic(key: "ios-general", title: "General issue"),
SupportTopic(key: "ios-problem", title: "Something is not working")
]
最佳配置小部件的位置是在 AppDelegate 的 didFinishLaunchingWithOptions
方法中。在那里您还应该从服务器中加载新文章。所以看起来是这样的:
let liveAgentWidget = TTLiveAgentWidget.getInstance()
liveAgentWidget.apiURL = "http://liveagent.server"
liveAgentWidget.apiKey = "123456"
liveAgentWidget.folderId = 10
liveAgentWidget.supportEmail = "[email protected]"
// Set topics
supportWidget.topics = [
SupportTopic(key: "ios-general", title: "General issue"),
SupportTopic(key: "ios-problem", title: "Something is not working")
]
liveAgentWidget.updateArticles(nil, onError: nil)
然后小部件的使用就像这样简单:
// Get Support widget instance
var supportWidget = TTLiveAgentWidget.getInstance()
// Open widget
supportWidget.open(fromController: self, style: .Push)
在 TTLiveAgentWidget 上,您可以编辑以下属性:
topics
- 知识库文章的主题maxArticlesCount
- 主题中的最大文章数supportEmail
- 支持电子邮件地址supportEmailSubject
- 支持电子邮件的主题supportEmailFooter
- 邮件尾部的参数字典apiURL
- 实时客服服务器 URLapiKey
- 实时客服 API 密钥(您应该使用代理服务器来隐藏您的 API 密钥)apiFolderId
- 包含知识库文章的实时客服文件夹 IDapiLimitArticles
- 来自实时客服 API 的文章限制如果您使用 TTLiveAgentWidgetStyle.Present
风格(不建议用于 TTLiveAgentWidgetStyle.Push
),您还可以通过以下属性配置导航栏的外观:
tintColor
- 导航栏颜色navigationBarCollor
- 导航栏背景颜色titleColor
- 导航栏标题颜色statusBarStyle
- 状态栏样式(UIBarStyle)使用样式从controller
打开小部件。样式可以是TTLiveAgentWidgetStyle.Present
(小部件将被呈现)或TTLiveAgentWidgetStyle.Push
(小部件将在导航控制器中滚动)。如果controller
未嵌入到UINavigationController
,则应使用TTLiveAgentWidgetStyle.Present
。如果小部件没有文章,则小部件将直接打开电子邮件窗口。
直接打开知识库文章。如果keyword
不在小部件的主题中,则小部件将以与open(fromController controller: UIViewController, style: Int)
相同的方式打开。
异步从Live Agent下载文章。你可以处理成功或错误状态。
打开小部件的电子邮件编写器。主题将添加到电子邮件的页脚。