Assistant & Resource Center in IOS
Deprecation notice
CommandBar is now part of Amplitude. This repository has been updated to help existing CommandBar customers migrate to Amplitude Resource Center & Assistant, but it should be treated as deprecated and will not receive updates.
CommandBarIOS is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CommandBarIOS'To install it using Swift Package Manager, add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/tryfoobar/CommandBarIOS.git", from: "1.1.9")
]
import CommandBarIOS
Boot CommandBar as early as possible in your app with your org ID from CommandBar. Optionally, you can pass a user_id for your currently logged in user to boot.
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Calling `.boot` prepares the SDK for use within your app
CommandBarSDK.shared.boot("<your org id>")
// (Optionally) Pass in a user_id with CommandBarOptions
CommandBarSDK.shared.boot("<your org id>", CommandBarOptions(user_id: "<your user id>"))
return true
}
}
// Inherit the CommandBarSDKDelegate protocol
class AppDelegate: UIResponder, UIApplicationDelegate, CommandBarSDKDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Calling `.boot` prepares the SDK for use within your app
CommandBarSDK.shared.boot("<your org id>")
}
// Conform to the protocol
func didFinishBooting(withError error: Error?) {
// If CommandBar failed to boot for some reason, an error will be passed, otherwise it will be null
}
}
Set filters before or after opening the sheet; the latest values are applied on each WebView load and immediately if the sheet is already open.
CommandBarSDK.shared.setAssistantFilter(["tags": ["[Zendesk] mobile"]])
let resourceCenterFilter: [String: Any] = [
"and": [
["tags": ["[Zendesk] mobile"]] as [String: Any],
["or": [
["tags": ["[Zendesk] v2"]] as [String: Any],
["tags": ["[Zendesk] v3"]] as [String: Any],
]] as [String: Any],
] as [String: Any],
]
CommandBarSDK.shared.setResourceCenterFilter(resourceCenterFilter)
CommandBarSDK.shared.setAssistantFilter(nil) // clearUse openResourceCenter to open the Help Hub tab, or openAssistant for the Assistant tab.
Once CommandBar is booted you can call CommandBarSDK.shared.openResourceCenter(). Please check out our Example app for usage as well as the sample below:
struct MyView: View {
var body: some View {
Button(action: {
CommandBarSDK.shared.openResourceCenter()
}) {
Text("Tap me!").padding()
}
}
}
Additionally, you can pass in an articleId to openResourceCenter to open a specific article in Help Hub.
struct MyView: View {
var body: some View {
Button(action: {
CommandBarSDK.shared.openResourceCenter(articleId: <article_id>)
}) {
Text("Tap me!").padding()
}
}
}
Additionally, you can pass in an fallbackAction to openResourceCenter or openAssistant to receive a callback when the user triggers an Open Chat action
struct MyView: View {
var body: some View {
Button(action: {
CommandBarSDK.shared.openResourceCenter(articleId: <article_id | null>, fallbackAction: {
print("User triggered Open Chat action")
CommandBarSDK.shared.closeResourceCenter()
})
}) {
Text("Tap me!").padding()
}
}
}
To run the example project, first clone the repo, then:
cd CommandBarIOS/Example && pod install- Open
Example/CommandBarIOS.xcworkspacein Xcode - Navigate to
HomeView.swiftand replace theORG_IDvariable with your Organization's ID from CommandBar - Run the App 🎉
CommandBarIOS is available under the MIT license. See the LICENSE file for more info.
