Unable to integrate Mopub's Native Ad into my UITableView for iOS

mopub
sdk

#1

I’m trying to integrate Mopub’s Native Ad into my UITableView for iOS and it’s not loading the ads.

The console says:

MOPUB: Received data from MoPub to construct native ad.     
MOPUB: Looking for custom event class named MPMoPubNativeCustomEvent.
MOPUB: Successfully loaded native ad.

but I don’t see any ads in my tableview.

Here is my test view controller used to integrate mopub:

import UIKit
import MoPub


class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MPTableViewAdPlacerDelegate {

    @IBOutlet weak var tableView: UITableView!
    let adUnitID = "my ad unit id"
    var placer:MPTableViewAdPlacer?
    var dataSource:[String]?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.tableView.mp_setDelegate(self)
        self.tableView.mp_setDataSource(self)
        
        self.tableView.register(UINib(nibName: "customCell", bundle: Bundle(for: customCell.self)), forCellReuseIdentifier: "cell")
        
        self.dataSource = [String]()
        
        for index in 0...20{
            self.dataSource?.append("My Index: \(index)")
        }
        
        self.setupAdPlacer()
        self.tableView.mp_reloadData()
    }
    
    func setupAdPlacer(){
        
        let targeting: MPNativeAdRequestTargeting! = MPNativeAdRequestTargeting()
        targeting.desiredAssets = Set([kAdIconImageKey, kAdCTATextKey, kAdTextKey, kAdTitleKey])
        
        let positioning:MPAdPositioning = MPAdPositioning()
        let settings:MPStaticNativeAdRendererSettings = MPStaticNativeAdRendererSettings()
        
        settings.renderingViewClass = NativeAdCell.self
        settings.viewSizeHandler = {(maxWidth: CGFloat) -> CGSize in
            let size:CGSize = CGSize(width: maxWidth, height: 333)
            return size
        }
        
        let config:MPNativeAdRendererConfiguration = MPStaticNativeAdRenderer.rendererConfiguration(with: settings)
        config.supportedCustomEvents = ["MPMoPubNativeCustomEvent"]
        
        self.placer = MPTableViewAdPlacer(tableView: self.tableView, viewController: self, adPositioning: positioning, rendererConfigurations: [config])
        self.placer?.delegate = self
        self.placer?.loadAds(forAdUnitID: adUnitID, targeting: targeting)
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (self.dataSource?.count)!
    }

    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.mp_dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? customCell
        
        if cell == nil {
            cell =  customCell()
        }
        
        let data = self.dataSource?[indexPath.row]
        cell?.myTextLabel?.text = data

        return cell! 
    }
}

My NativeAdCell Class:

import UIKit
import MoPub

class NativeAdCell: UITableViewCell, MPNativeAdRendering {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

#2

Hi @Iamarnold900,

Thanks for reaching out! Our Support Team should be able to help you get to the bottom of this based on your unique setup. Can you reach out to the team with the full, unfiltered device logs from your testing (including the ad request made by MoPub), the ad unit ID you are testing and the email address associated with your account?