Skip to content

tryfoobar/CommandBarIOS

Repository files navigation

CommandBar Logo

CommandBarIOS

Build

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.

Requirements

Installation

CocoaPods

CommandBarIOS is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CommandBarIOS'

Swift Package Manager

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")
]

Usage

1. Import the SDK

import CommandBarIOS

2. Initialize the SDK

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
    }
}

3. (Optional) Get notified of CommandBar boot status

// 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
    }
}

4. (Optional) Tag filters

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) // clear

5. (Optional) Open Resource Center / Assistant

Use 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()
    }
  }
}

5.(Optional) Run the Example App

To run the example project, first clone the repo, then:

  1. cd CommandBarIOS/Example && pod install
  2. Open Example/CommandBarIOS.xcworkspace in Xcode
  3. Navigate to HomeView.swift and replace the ORG_ID variable with your Organization's ID from CommandBar
  4. Run the App 🎉

License

CommandBarIOS is available under the MIT license. See the LICENSE file for more info.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors