我有一个
CollectionView
它有一个无限的卷轴,我正在努力使它,以便每9个细胞有一个AdMob横幅广告,而不是常规内容。
我想确保每个广告都与前一个不同。然而,据我所知,这意味着每一个新的广告都需要有一个新的
adUnitID
我必须通过AdMob网站手动创建。
是否可以显示
不同的
每隔9个手机打广告?
这就是我现在的代码。它可以工作,但它会一遍又一遍地显示同一个广告:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.item % 9 == 0) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: adCellId, for: indexPath) as! AdCell
let adSize = GADAdSizeFromCGSize(CGSize(width: self.view.frame.width, height: adViewHeight))
let bannerView = GADBannerView(adSize: adSize)
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.delegate = self
bannerView.rootViewController = self
bannerView.translatesAutoresizingMaskIntoConstraints = false
let request = GADRequest()
bannerView.load(request)
cell.contentView.addSubview(bannerView)
return cell
} else {
}
}
谢谢您!