Displaying ad from Admob to UITableViewController

I am trying to load native declarations into my UITableViewController that uses NSFetchedResultsController. There is nothing in the ads (only white spices). I have other ad types that are working correctly (Interstitial and Banner), so I know that Admob is configured correctly. Below is the relevant code:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellIdentifier = "MyCell"
    let adCellIdentifier = "AdCell"
    if 1 == indexPath.row % 10{
        let cell = tableView.dequeueReusableCell(withIdentifier: adCellIdentifier, for: indexPath) as! AdTableViewCell

        cell.expressNativeAd = createNativeAdExpress()

        return cell
    }
    let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
    let Item = self.fetchedResultsController.object(at: indexPath)
    self.configureCell(cell, withItem: Item)
    return cell
}

func createNativeAdExpress() -> GADNativeExpressAdView {
    let adUnitId = "ca-app-pub-#/#"
    let nativeAdView = GADNativeExpressAdView()
    nativeAdView.adUnitID = adUnitId
    nativeAdView.rootViewController = self
    nativeAdView.delegate = self

    let videoOptions = GADVideoOptions()
    videoOptions.startMuted = true
    nativeAdView.setAdOptions([videoOptions])

    nativeAdView.videoController.delegate = self

    let request = GADRequest()
    request.testDevices = [kGADSimulatorID]
    nativeAdView.load(request)

    return nativeAdView
}

      

In addition to having empty declarations, there is also a problem with configuring skipping elements returned by NSFetchedResultsController. If there are only four items returned, for example, the second cell will be an empty Ad cell, and then the third cell is the third item returned by the NSFetchedResultsController, instead of continuing from the second item.

In other words, because of adding the ad, I want 5 cells. 4 returned by NSFRC and 1 for advertisement, and for advertisement must not be empty.

adUnitID are the correct numbers in my code, not just # / # as I configured here.

expressNativeAd is of type GADNativeExpressAdView

+3


source to share





All Articles