Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

Prerequisites

  1. https://refinery89.atlassian.net/wiki/x/A4DVSQ

  2. https://refinery89.atlassian.net/wiki/x/BgDOSQ

The SDK provides a universal way to display advertisements inside the cell of scrollable controls, such as UITableView and UICollectionView.

Using a UITableView

We need you to edit your item Layout, so it has a wrapper/holder for the Ads.
Keep in mind this wrapper/holder could be expanded or contracted, so make sure your layout adapts to this changes, this size changes in the layout will be limited by the ad configurations that your technical account manager can edit.

This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll.

Get the UITableView

class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var tableView:UITableView!
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView = UITableView(frame: self.view.bounds, style: .plain)

        // Register a cell class
        tableView.register(InfScrlViewCell.self, forCellReuseIdentifier: "cell")
        
        tableView.delegate = self
        tableView.dataSource = self
        
        tableView.estimatedRowHeight = 300
        tableView.rowHeight = UITableView.automaticDimension

        self.view.addSubview(tableView)
        
        NSLayoutConstraint.activate([
            tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        ])
        ...
    }
 ...   
}

Adding the wrapper to the item

class InfScrlViewCell: UITableViewCell {

    let centeredLabel = UILabel()
    // This is the wrapper
    let adContainer:UIView = {
        let view = UIView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.accessibilityLabel = "infiniteScroll_ad_wrapper_tag"
        return view
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(centeredLabel)
        // Added the wrapper to the item
        contentView.addSubview(adContainer)
        // Setup the constraints
        ...
    }
    ...
}

Show the Ads

class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var tableView:UITableView!
    ...
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView = UITableView(frame: self.view.bounds, style: .plain)
        ...
        // Show the ads
        let infiniteScrollConfigId = ConfigBuilder.companion.INFINITE_SCROLL_TEST_R89_CONFIG_ID
        RefineryAdFactory.shared.createInfiniteScroll(
          configurationID: infiniteScrollConfigId, 
          scrollView: tableView, 
          scrollItemAdWrapperTag: TableViewInfiniteScrollViewController.tag, 
          lifecycleCallbacks: nil
        )
    }
 ...
}

  • No labels