Skip to main content

Getting Started

The LikeMinds Chat SDK allows you to seamlessly integrate personalized and engaging chats into your iOS application. This can significantly enhance the user experience and drive user engagement within your app. This getting started guide will walk you through the steps to integrate it into your application.

Prerequisites

Before you begin, ensure that you have the following:

  1. Xcode: Make sure you have Xcode 11 or above installed on your development machine.
  2. LikeMinds API Key: Sign up on the LikeMinds dashboard and obtain an API key for your application.

Dependencies

The SDK tries to keep the list of external dependencies to a minimum, these are the dependencies currently used:

LikeMindsChatUI

LikeMindsChatCore

LikeMindsChatData

Step-by-Step Integration Guide

Follow these steps to integrate the LikeMinds Chat SDK into your iOS application using CocoaPods:

Step 1 Install LikeMindsChatCore via CocoaPods:

Open your project's Podfile and add the following lines:

platform :ios, '13.0'

target 'YourProjectName' do
use_frameworks!
pod 'LikeMindsChatCore', '~> 1.7.0'
end

Then, run pod install from the terminal to install the required dependencies.

Step 2 - Set Up LikeMinds Chat:

In your AppDelegate.swift file, import the LikeMindsChatCore framework and set up the LikeMinds Chat in the application(_:willFinishLaunchingWithOptions:) method:

import LikeMindsChatCore

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMChatCore.shared.setupChat(deviceId: deviceId)
}
tip

It is advised to initiate LMChatCore at the beginning of your App Cycle.

Step 3 - Initiate User Session:

You have successfully initiated the LMChatCore. Now, when integrating the LikeMinds Chat SDK into your application, you provide the API Key directly to the LikeMinds Chat SDK, which will be used to initiate a user session by calling the showChat() method from LMChatCore.

import LikeMindsChatCore

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMChatCore.shared.showChat(apiKey: "YOUR_API_KEY", username: username, uuid: userId, completionHandler: { })
}
tip

For enhanced security, you can use Server Side User Authentication to initiate user sessions through your own server.

Step 4 - Navigation:

In the view controller where you want to display the LikeMinds Chat, import the LikeMindsChatCore framework and initialize the Chat with the appropriate user credentials:

import LikeMindsChatCore

let username = "USER_NAME"
let uuid = "USER_UUID"

try? LMChatCore.shared.showChat(apiKey: apiKey, username: username, userId: userId) {[weak self] result in
switch result {
case .success:
do {
let chatFeedVC = try LMChatFeedViewController.createModule()
self?.navigationController?.pushViewController(chatFeedVC, animated: true)
} catch {
let alert = UIAlertController(
title: "Error",
message: "Failed to open chat: \(error.localizedDescription)",
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self?.present(alert, animated: true)
}
case .failure(let error):
// Show error message
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(.init(title: "OK", style: .default))
self?.present(alert, animated: true)
return
}
}

Replace USER_NAME, USER_UUID and DEVICE_ID with the appropriate user credentials and device unique identifier for your application.

The createModule() method returns the view controller that displays the LikeMinds Chat. - In case of success, it sets the returned view controller as the root view controller of the application's window. - In case of failure, it displays an alert with the error message.

note

The view controller where you initialize the LikeMinds Chat should have a navigation controller, as the Chat requires navigation capabilities.

That's it! You have successfully integrated the LikeMinds Chat SDK into your iOS application. The next step would be to explore additional customization options or configurations provided by the SDK to tailor the Chat to your application's needs.