在 uitableviewcell 中集成 AdMob Native Ads Express?

integrating AdMob Native Ads Express in uitableviewcell?

我想在 uitableviewcell 中显示 Native Ads Express 我已经使用自定义 class

创建了自定义单元格
import UIKit
import GoogleMobileAds

class GoogleAdsCell: UITableViewCell {

    @IBOutlet weak var NativeAds: GADNativeExpressAdView!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        NativeAds.layer.cornerRadius = 2
        NativeAds.layer.shadowOffset = CGSizeMake(0, 0)
        NativeAds.layer.shadowOpacity = 1.0
        NativeAds.layer.shadowRadius = 6
        NativeAds.clipsToBounds = true
    }

}

并在 viewController 处的 cellForRowAtIndexPath

      let adsGoogleCell1 = tableView.dequeueReusableCellWithIdentifier("GoogleAdsCell") as! GoogleAdsCell 
      adsGoogleCell1.NativeAds.adUnitID = "ca-app-pub-3940256099942544/2562852117" 
      adsGoogleCell1.NativeAds.rootViewController = self 
      let request = GADRequest() 
      request.testDevices = [kGADSimulatorID] 
      adsGoogleCell1.NativeAds.loadRequest(request)
      return adsGoogleCell1

首先它起作用了,广告出现了,但过了一段时间它就消失了?

我遇到了完全相同的问题,并按照 github 的官方示例解决了。 这是https://github.com/googleads/googleads-mobile-ios-examples/tree/master/Swift/admob/NativeExpressExample

这是我的 cellForRowAt 方法的完整代码

let cell = tableView.dequeueReusableCell(withIdentifier: "MyTableBannerCell", for: indexPath) as! NewsDetailTableViewCell

cell.newsBottomBannerContainer.adUnitID = "native_express_ads_banner_id"
cell.newsBottomBannerContainer.rootViewController = self

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

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

return cell