TTLiveAgentWidget 0.1.2

TTLiveAgentWidget 0.1.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2015年6月
SPM支持 SPM

Lukáš Boura维护。



  • TappyTaps s.r.o.

使用 Swift编写的 iOS 实时客服小部件。

此小部件不仅是一个电子邮件类型的支持小部件。TTLiveAgentWidget 将知识库文章展示给用户,这样他们可以快速找到解决问题的方案。它与任何 API 版本为 1 的实时客服服务器一起工作。

为了更好的性能和安全性,我们建议使用代理服务器。请参阅我们的代理服务器 TTLiveAgentWidget-ProxyServer

安装

  • 需要 iOS 8.0+

手动将 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 - 实时客服服务器 URL
  • apiKey - 实时客服 API 密钥(您应该使用代理服务器来隐藏您的 API 密钥)
  • apiFolderId - 包含知识库文章的实时客服文件夹 ID
  • apiLimitArticles - 来自实时客服 API 的文章限制

如果您使用 TTLiveAgentWidgetStyle.Present 风格(不建议用于 TTLiveAgentWidgetStyle.Push),您还可以通过以下属性配置导航栏的外观:

  • tintColor - 导航栏颜色
  • navigationBarCollor - 导航栏背景颜色
  • titleColor - 导航栏标题颜色
  • statusBarStyle - 状态栏样式(UIBarStyle)

API

open(fromController controller: UIViewController, style: Int)

使用样式从controller打开小部件。样式可以是TTLiveAgentWidgetStyle.Present(小部件将被呈现)或TTLiveAgentWidgetStyle.Push(小部件将在导航控制器中滚动)。如果controller未嵌入到UINavigationController,则应使用TTLiveAgentWidgetStyle.Present。如果小部件没有文章,则小部件将直接打开电子邮件窗口。

open(fromController controller: UIViewController, keyword: String, style: Int)

直接打开知识库文章。如果keyword不在小部件的主题中,则小部件将以与open(fromController controller: UIViewController, style: Int)相同的方式打开。

updateArticles(onSuccess: (()->Void)?, onError: (()->Void)?)

异步从Live Agent下载文章。你可以处理成功或错误状态。

openEmailComposer(fromController controller: UIViewController, topic: SupportTopic?)

打开小部件的电子邮件编写器。主题将添加到电子邮件的页脚。