MENU

Introduction

The LiveChat Widget for iOS allows the app users to contact the chat agents directly from a mobile application. The widget is very easy for developers to integrate into their existing iOS apps.

The source code and installation instructions can be found on GitHub.

Version 2.0 of the widget has several significant improvements over the previous version that can be found here.

Requirements

Installation

You integrate LiveChat into your project manually or with a dependency manager.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

Install it with the following command:

$ gem install cocoapods

To integrate LiveChat into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'LiveChat', '~> 2.0'
end

Then, run the following command:

$ pod install

Manual Installation

You can integrate LiveChat into your project manually without using a dependency manager.

Swift

Just drag all files from the LiveChat/Classes directory into your project.

Objective-C

Drag all files from the LiveChat/Classes directory into your project. When adding thefirst *.swift file to Objective-C project, Xcode will ask you to create a Bridging Header. It is not necessary for LiveChat to work, so you can decline unless you plan to call Swift code from Objective-C. More information about bridging headers and Swift and Objective-C interoperability can be found here. You need to put the following import statement: #import "<Your Project Name>-Swift.h" at the top of your .m file.

Also, for Objective-C projects, you need to set the Embedded Content Contains Swift Code flag in your project to Yes (found under Build Options in the Build Settings tab).

Usage

Initalization

import LiveChat

LiveChat.licenseId = "YOUR_LICENSE_ID"

Presenting Chat Widget

LiveChat.presentChat()

Setting Custom Variables

You can provide customer name or email if they are known, so a customer will not need to fill out the pre-chat survey:

LiveChat.name = "iOS Widget Example"
LiveChat.email = "example@livechatinc.com"

If you want to associate some additional info with your customer, you can set up Custom Variables:

LiveChat.setVariable(withKey:"Variable name", value:"Some value")

Assign chat to specific group

You can route your customers to specific group of agents by providing groupId. More information can be found here: https://www.livechatinc.com/kb/dividing-live-chat-by-group/.

LiveChat.groupId = "7"

Notifying the user about the agent's response

class YOUR_CLASS_NAME : LiveChatDelegate { // Your class need to implement LiveChatDelegate protocol
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        LiveChat.licenseId = "YOUR_LICENSE_ID"
        LiveChat.delegate = self // Set self as delegate

        return true
    }

    func received(message: LiveChatMessage) {
        print("Received message: \(message.text)")
        // Handle message here
    }
}

You can notifiy your user about the agent's response if the chat has been minimized by the user. To handle the incoming messages, your class must implement the LiveChatDelegate protocol and set itself as LiveChat.delegate.

Handling URL

func handle(URL: URL) {
    print("URL is \(URL.absoluteString)")
    // Handle URL here
}

By default, all links in the chat messages are opened in Safari browser. To change this behavior you can use LiveChatDelegate to handle the URLs yourself.

Sending Photos from the device library

If you have file sharing enabled for the visitors, you should provide the usage description by including the NSPhotoLibraryUsageDescription (Privacy - Photo Library Usage Description) key in your Info.plist file to avoid crash on iOS 10 or higher.

Sample Apps

Sample apps for both Swift and Objective-C can be found in the Examples folder.

Getting help

If you have any questions or want to provide feedback, chat with us!

License

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