Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google advertisements on infinite feed implementation issue #272

Open
lzouloumis opened this issue Jun 2, 2022 · 3 comments
Open

Google advertisements on infinite feed implementation issue #272

lzouloumis opened this issue Jun 2, 2022 · 3 comments
Assignees

Comments

@lzouloumis
Copy link

lzouloumis commented Jun 2, 2022

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?

@asolanki-in
Copy link

I also would like to see infinite list implementation for BannerAds in SwiftUI

@Djallil14
Copy link

@JillSong JillSong self-assigned this Nov 13, 2023
@JillSong
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants