Getting Started
The LikeMinds Feed SDK allows you to seamlessly integrate personalized and engaging feeds 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:
- Xcode: Make sure you have the latest version of Xcode installed on your development machine.
- Minimum iOS Version: Your project should target iOS 13.0 or later.
- CocoaPods: Ensure you have CocoaPods installed for dependency management.
Dependencies
The SDK tries to keep the list of external dependencies to a minimum, these are the dependencies currently used:
LikeMindsFeedUI
LikeMindsFeedUI doesn't depends on any external packages
LikeMindsFeedCore
LikeMindsFeed
Step-by-Step Integration Guide
Follow these steps to integrate the LikeMinds Feed SDK into your iOS application using CocoaPods:
Step 1 Install LikeMindsFeedCore via CocoaPods:
Open your project's Podfile
and add the following lines:
platform :ios, '13.0'
target 'YourProjectName' do
use_frameworks!
pod 'LikeMindsFeedCore'
end
Then, run pod install
from the terminal to install the required dependencies.
Step 2 - Set Up LikeMinds Feed:
In your AppDelegate.swift
file, import the LikeMindsFeedCore
framework and set up the LikeMinds Feed in the application(_:willFinishLaunchingWithOptions:)
method:
import LikeMindsFeedCore
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMFeedCore.shared.setupFeed(deviceId: deviceId)
}
Step 3 - Initialise LikeMinds Feed:
You have successfully initiated the LMFeedCore. Now, When integrating the LikeMinds Feed SDK into your application, you have the option to initiate a user session using one of two approaches:
With API Key
This approach should be used when you want to manage LikeMinds authentication tokens on frontend. In this case, you provide API Key directly to LikeMinds Feed SDK, which will be used to initiate a user session by calling showFeed()
method from LMFeedCore.
import LikeMindsFeedCore
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMFeedCore.shared.showFeed(apiKey: "YOUR_API_KEY", username: username, uuid: userId, completionHandler: { })
}
Replace YOUR_API_KEY
with the API key you obtained from the LikeMinds dashboard.
It is advised to initiate LikeMindsFeed at the beginning of your App Cycle
Without API Key
This approach should be used when you want to manage LikeMinds authentication tokens on your backend server. In this case, you eliminate the need to expose your API Key to your client app and your backend server is responsible for calling the initiate API to obtain the accessToken
and refreshToken
which is passed to showFeed()
from LMFeedCore
to validate the user session.
Create a function to get
accessToken
andrefreshToken
from your backend using the initiate API.Implement the
LMFeedCoreCallback
protocol in your class:
public protocol LMFeedCoreCallback: AnyObject {
func onAccessTokenExpiredAndRefreshed(accessToken: String, refreshToken: String)
func onRefreshTokenExpired(_ completionHandler: (((accessToken: String, refreshToken: String)) -> Void)?)
}
Example
class ClientSDKCallBack: LMFeedCoreCallback {
func onAccessTokenExpiredAndRefreshed(accessToken: String, refreshToken: String) {
// Store the updated tokens
}
func onRefreshTokenExpired(_ completionHandler: (((accessToken: String, refreshToken: String)?) -> Void)?) {
// Call inititate api from your backend and return the fetched accessToken and refreshToken
// completionHandler?((accessToken, refreshToken))
// In case the call fails, return nil
// completionHandler?(nil)
}
}
This protocol has two methods:
onAccessTokenExpiredAndRefreshed
: Called when the access token expires and is refreshed internally.onRefreshTokenExpired
: Called when the refresh token expires. You need to provide new tokens from your backend.
- Upon receiving the
accessToken
andrefreshToken
from your backend server, callLMFeedCore.shared.showFeed()
function with these tokens.
import LikeMindsFeedCore
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
// Pass the earlier created Implementation of LMFeedCoreCallback
LMFeedCore.shared.showFeed(accessToken: accessToken, refreshToken: refreshToken, handler: ClientSDKCallback(), completionHandler: { })
}
Step 4 - Navigation:
In the view controller where you want to display the LikeMinds Feed, import the LikeMindsFeedCore
framework and initialize the feed with the appropriate user credentials:
- Social Feed
- QnA Feed
import LikeMindsFeedCore
let username = "USER_NAME"
let uuid = "USER_UUID"
try? LMFeedCore.shared.showFeed(apiKey: apiKey, username: username, userId: userId) {[weak self] result in
switch result {
case .success:
guard let viewController = try? LMFeedSocialFeedViewModel.createModule() else {
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(.init(title: "OK", style: .default))
self?.present(alert, animated: true)
return
}
let navigationController = UINavigationController(rootViewController: viewController)
UIApplication.shared.windows.first?.rootViewController = navigationController
UIApplication.shared.windows.first?.makeKeyAndVisible()
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
}
}
import LikeMindsFeedCore
let username = "USER_NAME"
let uuid = "USER_UUID"
try? LMFeedCore.shared.showFeed(apiKey: apiKey, username: username, userId: userId) {[weak self] result in
switch result {
case .success:
guard let viewController = try? LMFeedQnAFeedViewModel.createModule() else {
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(.init(title: "OK", style: .default))
self?.present(alert, animated: true)
return
}
let navigationController = UINavigationController(rootViewController: viewController)
UIApplication.shared.windows.first?.rootViewController = navigationController
UIApplication.shared.windows.first?.makeKeyAndVisible()
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
}
}
The createModule()
method returns the view controller that displays the LikeMinds Feed. - 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.
The view controller where you initialize the LikeMinds Feed should have a navigation controller, as the Feed requires navigation capabilities.
That's it! You have successfully integrated the LikeMinds Feed SDK into your iOS application. The next step would be to explore additional customization options or configurations provided by the SDK to tailor the Feed to your application's needs.