GithubHelp home page GithubHelp logo

naikdp7 / chat-window-ios-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from livechat/chat-window-ios

0.0 0.0 0.0 356 KB

Embeding LiveChat mobile chat window in iOS application

License: MIT License

Swift 95.69% Ruby 1.04% JavaScript 2.68% Objective-C 0.59%

chat-window-ios-1's Introduction

iOS chat widget for LiveChat

iOS chat widget for LiveChat allows you to integrate LiveChat with your iOS app.

Carthage compatible Version License Platform

Requirements

  • iOS 11.0+
  • Xcode 10.0+

Installation

Carthage

If you use Carthage to manage your dependencies, simply add 'livechat/chat-window-ios' to your Cartfile.

github "livechat/chat-window-ios" ~> 2.0.24

Make sure you have added LiveChat.framework to the "Linked Frameworks and Libraries" section of your target, and have include it in your Carthage framework copying build phase.

CocoaPods

If you use CocoaPods to manage your dependencies, simply add LiveChat to your Podfile.

pod 'LiveChat', '~> 2.0.24'

Manual Installation

You can integrate iOS chat widget into your project manually without using a dependency manager.

Swift

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

Objective-C

Drag all files from the LiveChat/Sources directory into your project. When adding first *.swift file to Objective-C project, Xcode will ask you to create a Bridging Header. It is not necessary for chat widget 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"

Default Chat Widget presentation

LiveChat.presentChat()

Presenting Chat Widget within client app view hierarchy

You can also take over the a responsibility for widget presentation within you app. To do so you have to set the customPresentationStyleEnabled flag to true. This flag will disable the default widget's presentation behavior and leave that logic up to you. You can now access the chatViewController property and define your own presentation style.

When customPresentationStyleEnabled is set to false then chatViewController has a value of nil.

class YOUR_CLASS_NAME : UIViewControler, LiveChatDelegate { // Your class need to implement LiveChatDelegate protocol

    @IBAction func openChat(_ sender: Any) {  
        LiveChat.delegate = self
        LiveChat.customPresentationStyleEnabled = true

        present(LiveChat.chatViewController!, animated: true) {
            print("Presentation completed")
        }
    }

    func chatDismissed() {
        LiveChat.chatViewController!.dismiss(animated: true) {
            print("Presentation dismissed")
        }
    }
}

Using UIWindowSceneDelegate

If your app is using UIWindowScene API you need to perform additional configuration steps in you window scene delegate class.

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        LiveChat.windowScene = (scene as? UIWindowScene)
    }
}

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 = "[email protected]"

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 = "77"

Notifying the user about the agent's response

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

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

Sample message structure.

{
    author = {
        name = "Support Bot";
    };
    id = "QZ0X4O6PAV_3";
    messageType = newMessage;
    text = "I'm a HelpDesk Bot, here to assist you with any HelpDesk questions!";
    timestamp = 1632478822776;
}

Handling chat window resence events

On the SDK level it's also possible to handle chat window presence events. To do so, your class must implement LiveChatDelegate protocol and set itself as LiveChat.delegate.

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 chatPresented() {
        print("Chat presented")
        // Handle event here
    }
    
    func chatDismissed() {
        print("Chat dismissed")
        // Handle event here
    }    
}

Handling URL

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

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

Handling chat window errors

SDK will use this method to report unhandled widget errors.

func loadingDidFail(with errror: Error) {
    print("Chat loading failure \(errror)")
    // Handle error here
}

Sending files from device library

If you have file sharing enabled for the visitors, you should provide usage description by including NSPhotoLibraryUsageDescription (Privacy - Photo Library Usage Description), NSCameraUsageDescription (Privacy - Camera Usage Description) and NSMicrophoneUsageDescription (Privacy - Microphone Usage Description) keys in your Info.plist file to avoid crash on iOS 10 or higher. You can check Info.plist files in example projects.

Third party integrations

Snap Call

LiveChat SDK offers built in Snap Call (https://snapcall.io) integration. To benefit from that feature you have to prepare you application for requesting a mic permission from the user. That can be done by adding NSMicrophoneUsageDescription and NSCameraUsageDescription keys to the Info.plist file.

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.