Advanced Options
iOS Classic - Advanced Options
Multiple Taboola Units on 1 page
By default, if a given screen/page contains multiple Taboola Units, each Unit loads sequentially. This flow enables Taboola to prevent duplicate content across Units.
You can customize this default behavior at the Page level - as described below.
Parallel loading
By default, Taboola SDK uses serial loading (FetchingPolicySerial
). To adjust this default behavior, set the fetchingPolicy
property.
When loading Units in parallel, Taboola cannot guarantee unique content across Units.
After initializing TBLClassicPage
:
_classicPage.fetchingPolicy = FetchingPolicyParallel;
classicPage?.fetchingPolicy = FetchingPolicy.parallel
Possible values:
FetchingPolicySerial
- serial loading of Units (default).FetchingPolicyParallel
- parallel loading of Units.
Publisher manages the cell
As mentioned under Basic Integration > Manage the layout, we recommend using Taboola SDK to manage the cell.
If you prefer to manage the cell yourself, follow the steps in this section.
Cell management
The following code fragment illustrates the overall concept for managing the cell yourself:
// sizeForItemAtIndexPath
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
// Widget size...
return CGSizeMake(self.view.frame.size.width, _widgetUnit.placementHeight);
// Feed size...
return CGSizeMake(self.view.frame.size.width, feedUnit.placementHeight);
}
// cellForItemAtIndexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Widget...
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TaboolaCollectionViewCell" forIndexPath:indexPath];
// Remove Taboola from the cell
for (UIView *view in [cell.contentView subviews]) {
[view removeFromSuperview];
}
// Add Widget to the cell
[cell.contentView addSubview:_widgetUnit];
return cell;
// Feed...
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TaboolaCollectionViewCell" forIndexPath:indexPath];
// Remove Taboola from the cell
for (UIView *view in [cell.contentView subviews]) {
[view removeFromSuperview];
}
// Add Feed to the cell
[cell.contentView addSubview:_feedUnit];
return cell;
}
// sizeForItemAt
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// Widget size...
return CGSize(width: self.view.frame.size.width, height: widgetUnit?.placementHeight ?? 200)
// Feed size...
return CGSize(width: self.view.frame.size.width, height: feedUnit?.placementHeight ?? 200)
}
// cellForItemAt
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// Widget cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TaboolaCollectionViewCell", for: indexPath)
if let widgetUnit = widgetUnit {
// Remove Taboola from the cell
for view in cell.contentView.subviews{
view.removeFromSuperview()
}
// Add Widget to the cell
cell.contentView.addSubview(widgetUnit)
}
return cell
// Feed cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TaboolaCollectionViewCell", for: indexPath)
if let feedUnit = feedUnit {
// Remove Taboola from the cell
for view in cell.contentView.subviews {
view.removeFromSuperview()
}
// Add Feed to the cell
cell.contentView.addSubview(feedUnit)
}
return cell
}
When managing the cell yourself, you also need to handle the didLoadOrResizePlacement
event - described next.
didLoadOrResizePlacement event
Returns the loaded placement with its updated height.
Only required when managing the cell yourself (see above).
We recommend using Taboola SDK to manage the cell. See: Basic Integration > Manage the layout.
-(void)taboolaView:(UIView *)taboolaView didLoadOrResizePlacement:(NSString *)placementName withHeight:(CGFloat)height placementType:(PlacementType)placementType{
NSLog(@"%@", placementName);
// If Taboola manages the UI (*recommended*), then NO special handling is required here.
// Else - insert your code here:
if ([placementName containsString:widgetPlacement]) {
// Widget
[_widgetUnit setFrame:CGRectMake(0, 0, self.view.frame.size.width, _widgetUnit.placementHeight)];
} else {
// Feed
[_feedUnit setFrame:CGRectMake(__feedUnit.frame.origin.x, __feedUnit.frame.origin.y, self.view.frame.size.width, __feedUnit.placementHeight)];
}
[self.collectionView.collectionViewLayout invalidateLayout];
}
func taboolaView(_ taboolaView: UIView!, didLoadOrResizePlacement placementName: String!, withHeight height: CGFloat, placementType: PlacementType) {
print("Placement name: \(String(describing: placementName)) has been loaded with height: \(height)")
// If Taboola manages the UI (*recommended*), then NO special handling is required here.
// Else - insert your code here:
if placementName == Constants.widgetPlacement{
// Widget
widgetUnit?.frame = CGRect(x: 0,y: 0,width: self.view.frame.size.width,height: widgetUnit?.placementHeight ?? 200)
}
else {
// Feed
feedUnit?.frame = CGRect(x: feedUnit?.frame.origin.x ?? 0,y: feedUnit?.frame.origin.y ?? 0,width: self.view.frame.size.width,height: feedUnit?.placementHeight ?? 200)
}
self.collectionView.collectionViewLayout.invalidateLayout()
}
Params
placementName
- The name of the placement loaded/resized.height
- The height, in pixels, of the placement loaded/resized.placementType
- Widget or Feed.
Insert resizing code for both Widget and Feed.
For additional events, see: Event Handling.
Dark Mode
Configuring Dark Mode
Dark mode is not supported by default. For dark-mode placements, contact your Taboola Account Manager.
Once Taboola has configured your dark-mode placements, you can use the following code in your application:
[_classicPage setPageExtraProperties:@{@"darkMode":@"true"}];
classicPage?.pageExtraProperties = ["darkMode":"true"]
Swapping Between Dark & Light Themes
Setting extraProperties with "darkMode" "true" will send a request for "dark" content.
For light content do not set the extra Property and avoid using ["darkMode":"false"]
Need a hand?
Go ahead! Ask a question in our Support Forum.
Tip: Provide as much detail as possible, including your platform and SDK version.
Updated 13 days ago