Forethought - Solve iOS SDK
此仓库包含 Forethought iOS SDK 的框架和说明。
为了使用 Forethought Solve SDK,需要一个有效的 API 密钥。除了下面的文档外,还编写了 Objective-C & Swift 的示例应用程序,以及 SwiftUI 的实现。
安装
Swift 包管理器
-
在 Xcode 中,选择 文件 > 添加包。
-
输入 Forethought iOS GitHub 仓库 URL(
https://github.com/Forethought-Technologies/solve-ios
) -
点击 添加包。按提示操作,Xcode 将自动下载框架。
Cocoapods
-
Forethought 也可通过 CocoaPods 获取。
-
在
Podfile
文件中添加以下行pod 'Forethought'
-
运行以下命令
$ pod install
-
请确保从此以后使用
.xcworkspace
文件且 不要 使用.xcodeproj
。
基本用法
- 在
AppDelegate.swift
文件中,将__YOUR_KEY_HERE__
替换为有效的 Forethought API 密钥ForethoughtSDK.start(apiKey: "__YOUR_KEY_HERE__")
- 打开 Forethought 小部件
import 'Forethought' ForethoughtSDK.show()
可选添加
工作流程上下文变量
传递通过 Forethought 控制面板定义的工作流程上下文变量
ForethoughtSDK.dataParameters = ["language":"EN", "user-email": "[email protected]", "workflow-context-variable": "value"]
移交方法
将客户从Forethought转移至Kustomer等代理聊天服务提供者
- 将委托设置为Forethought SDK。在展示界面之前完成此操作
ForethoughtSDK.delegate = self
- 确保对象符合ForethoughtDelegate协议
class ViewController: UIViewController, ForethoughtDelegate {
- 通过添加以下方法来符合ForethoughtDelegate
func startChatRequested(handoffData: ForethoughtHandoffData) {}
- 在此添加移交实现。例如。
Kustomer.show(...) Kustomer.startNewConversation(...)
- 移交完成后,
sendHandoffResponse
将根据是否成功将对话传递给代理聊天服务提供者来继续或更新Forethought对话。ForethoughtSDK.sendHandoffResponse(success: true)
移交示例
func startChatRequested(handoffData: ForethoughtHandoffData) {
print("Chat Requested: \(handoffData)")
// close forethought widget
ForethoughtSDK.hide(animated: false)
// start a Kustomer chat
Kustomer.startNewConversation(initialMessage: KUSInitialMessage(body: handoffData.question, direction: .user))
// if handoff was successful
ForethoughtSDK.sendHandoffResponse(success: true)
// if handoff was unsuccessful
ForethoughtSDK.show()
ForethoughtSDK.sendHandoffResponse(success: false)
}
直接使用导航控制器
直接在导航堆栈上附加Forethought SDK
@IBAction func contactSupportTapped() {
ForethoughtSDK.show(fromNavigationController: self.navigationController)
}
插件
⛔️ 从2.0.0版本开始,插件已被弃用 ⛔️
文档
已提供文档为.doccarchive格式,以便直接在Xcode中查看完整文档。使用时,只需双击Forethought.doccarchive即可,Xcode将处理其余操作。