jenkins-ci
jenkins-ci copied to clipboard
Google advertisements on infinite feed implementation issue
Hello,
We have followed your implementation to embed GAMBannerViews on a UITableView. The only thing that is different in our implementation is that our feed has infinite pagination and our cache stores the GAMBannerView instance as a value instead of key. Our cache look like this:
var advertisementsCache: [String: GAMBannerView] = [:]
However, due to the nature of our feed that has infinite pagination our cache keeps on growing as we scroll and load more ads and the device starts to overheat and finally lags terribly.
We have tried to solve this issue by removing the cache and utilise the reuse functionality of the tableview but we have found that as the tableview's cells get reused our code loads new ads constantly. While scrolling up for instance our code will trigger the ad request again.
Implementation code without cache:
`class AdTableViewCell: UITableViewCell {
func configure(data: AdvertisementModel) {
if contentView.subviews.isEmpty {
let view = GAMBannerView(adSize: GADAdSizeMediumRectangle)
view.adUnitID = data.id
view.delegate = data.googleAdvertisementMetadata.delegate as? GADBannerViewDelegate
view.rootViewController = data.googleAdvertisementMetadata.rootViewController
contentView.addSubview(view)
view.anchorCenterSuperview()
let request = GAMRequest()
request.customTargeting = AdTargetingManager().makeCustomAdTargetingDictionary(metadata: AdTargetingMetadata.toEntity(data: data.googleAdvertisementMetadata.targetingMetadata))
view.load(request)
return
}
guard let banner = contentView.subviews.first as? GAMBannerView else { return }
banner.adUnitID = data.id
banner.delegate = data.googleAdvertisementMetadata.delegate as? GADBannerViewDelegate
banner.rootViewController = data.googleAdvertisementMetadata.rootViewController
let request = GAMRequest()
request.customTargeting = AdTargetingManager().makeCustomAdTargetingDictionary(metadata: AdTargetingMetadata.toEntity(data: data.googleAdvertisementMetadata.targetingMetadata))
banner.load(request)
}
} `
To conclude, by using a cache we overload the phone's ram and by disabling the cache the reuse of the table view triggers all the time requests to google as we scroll.
We don't know if there is a possible optimal solution to embedding banner view on a tableview with infinite pagination. Would you please help us?
I also would like to see infinite list implementation for BannerAds in SwiftUI
➕
@lzouloumis Thank you for your suggestion. I agree our sample should displays infinite scroll view. I'm raising a feature request internally to track the update to this repo. Will let you know here when the changes are out.