The first thing you need to do is adding the SDK in your project.

Alli SDK requires iOS 11 or above.

Step 1. Download and unzip the SDK

  1. Download the SDK here.
  2. After unzipping the SDK, you should see the following files in the folder:

Step 2. Add SDK to your project

  1. Right click the Project Icon in your Project Navigator in Xcode.
  2. Click the Add Files to "Your App"... button. A dialog will appear.
  3. Select the AlliFramework folder.
  4. Make sure your dialog looks like the following, then click the Add button

Step 3. Add embedded binaries, frameworks & libraries

  1. Click on your Project Icon in the Project Navigator.
  2. Select "Build Phases", expand "Link -> Phases", then expand "Link Binary With Libraries".
  3. Click the "+" symbol in the lower left of the section.
  4. Add AlliFramework.framework
  5. Repeat the steps to add AlliFramework.framework in “Embed Frameworks”

Steps 4. Specify permission in Info.plist

Open your info.plist file and select the “+” symbol next to Information Property list and scroll through the dropdown list to the Privacy options and select Privacy Camera Usage Description for accessing camera or Privacy Photo Library Usage Description for accessing the Photo Library. This will permit users to upload receipt files or product images into chat. Fill in the String value on the right after you've made your selection to include the text you would like displayed to your user when the alert pop up asks for permissions.

Step 5. Initialize Alli SDK

  1. Add import AlliFramework to the beginning of your application’s delegate class file ViewController.swift. This will make the Alli framework accessible to your project.
  2. Initialize the Alli library with your API Key by adding the following in your ViewController.
  var alli: Alli?
  override func viewDidLoad() {
    alli = Alli("YOUR_API_Key", eventHandler: self)
  }

You can find your API Key by selecting “Settings” from the left navigation:

Step 6. Identify your users

For users logged into your app and you know who they are, you can tell Alli who they are. You can also set a temporary id for users who are not logged in.

In this example, the user id is USER-123 at the LANDING page:

var alli: Alli?

override func viewDidLoad() {
	alli = Alli("YOUR_API_Key", eventHandler:self)
	userId.text = "USER-123"
	placement.text = "LANDING"
	notify.text = "UNINITIALIZED"
}

Step 7. Create chat window

To create the chat window and start a conversation with your customer, make the following call:

alli!.event(userId:userId, placement:placement, view:parentView)

You should implement the Alli chat window in the parent view controller and assign the parent view controller as the delegate property. It is vitally important that the ViewController passed to this call be the top-most view and that it be unobstructed by other views.

Parent view should have a minimum height and width

Step 8: Delegate methods to handle Alli events

The following delegate methods will provide feedback on the chat conversation status:

  public protocol AlliEventHandler {
    // Called when initialized successfully. 
    // You may receive NOT_INITIALIZE_YET error if 
    // called before this event.
    func onInitialized(_ view:WKWebView!)

    // Called when chat started successfully.
    func onConversationStarted(_ view: WKWebView!, userId: String, placement: String, context: Any?)

    // Called when conversation did not start 
    // even when Alli.event was called.
    func onConversationNotStarted(_ view: WKWebView!, userId: String, placement: String, context: Any?)

    // Called when user has closed the chat 
    // window or Alli.close() is called.
    func onConversationStopped(_ view: WKWebView!, userId: String, placement: String, context: Any?)

    func onError(_ view: WKWebView!, errorCode: AlliErrorCode, userId:String?, placement:String?, context:Any?)
  }

Step 10: Display chat interface

By default, the chat window should be set to hidden when no conversation is engaged:

  func onConversationStopped(_ view: WKWebView!, userId: String, placement: String, context: Any?) {
  	parentView.isHidden = true
  }

When you receive AlliEventHandler.onConversationStarted event, changes the chat window to visible:

  func onConversationStarted(_ view: WKWebView!, userId: String, placement: String, context: Any?) {
    parentView.isHidden = false
  }