The Taboola Lite SDK allows developers to easily integrate Taboola's personalized content recommendations into their iOS applications. This documentation provides all the necessary steps and details to set up and use the SDK.
Before you begin, ensure your project meets the following requirements:
- Minimum iOS Version: 14.0
- Xcode: 13.0 or later
- Swift: 5.0 or later
- In Xcode, go to File > Add Packages
- Enter the package URL:
https://github.com/taboola/taboola-ios-lite
- Select the version you want to use by setting the branch name
- Click Add Package
- Download the latest release from GitHub
- Drag the
TaboolaLite.xcframework
into your Xcode project - Make sure "Copy items if needed" is checked
- Select your target and click "Embed & Sign"
The TBLSDK.initialize
method must be called before using any other SDK functionality. Initialize the SDK in your AppDelegate
:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let publisherId = "your-publisher-id"
let userData = TBLUserData(
"hashedEmail",
"gender",
"age",
"userInterestAndIntent"
)
TBLSDK.shared.initialize(publisherId: publisherId, data: userData)
return true
}
Once the SDK is initialized, you can add Taboola content to any view:
class NewsViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
TBLSDK.shared.addTaboolaNewsToView(view)
}
}
When you're done with the Taboola content, remove it from the view:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
TBLSDK.shared.removeTaboolaNewsFromView()
}
You can update user data at any time:
let userData = TBLUserData(
"hashedEmail1",
"gender",
"age",
"userInterestAndIntent"
)
TBLSDK.shared.setUserData(userData)
To properly clean up SDK resources when the app terminates, add the following to your AppDelegate:
func applicationWillTerminate(_ application: UIApplication) {
TBLSDK.shared.deinitialize()
}
This ensures that all SDK resources are properly released when the app is terminated.
Implement the OnTaboolaNewsListener
protocol to handle Taboola events:
class NewsViewController: UIViewController, OnTaboolaNewsListener {
override func viewDidLoad() {
super.viewDidLoad()
TBLSDK.shared.setOnTaboolaNewsListener(self)
}
func onTaboolaNewsFailed(statusCode: TBLStatusCode) {
print("Taboola failed with status code: \(statusCode)")
}
func onTaboolaNewsSharePressed(url: String) {
// Handle share action
let activityVC = UIActivityViewController(
activityItems: [url],
applicationActivities: nil
)
present(activityVC, animated: true)
}
}
The SDK uses the following status codes:
public enum TBLStatusCode: Int {
case success = 200
case badRequest = 400
case serviceUnavailable = 503
case publisherInvalid = -1
}
Each status code has a corresponding message that can be accessed via the message
property.
When you're done listening to events:
TBLSDK.shared.removeOnTaboolaNewsListener()
When your app goes to background or returns to foreground:
// In AppDelegate
func applicationDidEnterBackground(_ application: UIApplication) {
TBLSDK.shared.onPauseTaboolaNews()
}
func applicationWillEnterForeground(_ application: UIApplication) {
TBLSDK.shared.onResumeTaboolaNews()
}
To programmatically scroll the Taboola content to the top:
TBLSDK.shared.onScrollToTopTaboolaNews()
To control the log verbosity of the SDK, you can set the log level as follows:
TBLSDK.shared.setLogLevel(TBLLogLevel.debug) // Options: .error, .warn, .info, .debug
For testing purposes, you can configure the reload intervals for the WebView content:
TBLSDK.shared.updateReloadIntervals(
1, // Set WebView reload interval to 1 minutes
1 // Set timer repeat interval to 1 minutes
)
- Added updateReloadIntervals method for testing WebView reload behavior
- Added setLogLevel method for controlling SDK log verbosity
- Initial release of the Taboola Lite SDK
- Includes user data configuration and publisher-specific settings
- Provides lifecycle management for proper SDK initialization and cleanup
- Supports event handling for Taboola content interactions