0

I have a collection view in my project with lots of data coming from a web service, with GADBAnnerView(AdMob) on every 4th position. Ads are showing but it doesn't scroll smoothly.

- (void)preloadNextGoogleBannerAd {
if (!adMobBannersToLoad.count) {
    return;
}
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    GADBannerView *adView = adMobBannersToLoad.firstObject;
    [adMobBannersToLoad removeObjectAtIndex:0];
    GADRequest *request = [GADRequest request];
    request.testDevices = @[ kGADSimulatorID ];
    dispatch_async(dispatch_get_main_queue(), ^(void){
       [adView loadRequest:request];
    });
});

And in cellForItemAtIndexPath of CollectionView

for (UIView *subview in reusableAdCell.contentView.subviews) {
  [subview removeFromSuperview];
}

GADBannerView *adView = _tableViewItems[indexPath.row];
[reusableAdCell.contentView addSubview:adView];
adView.center = reusableAdCell.contentView.center;

return reusableAdCell;

Can someone help me for this issue?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Akhil
  • 93
  • 7
  • Hi, can you add a screenshot? Do you have a 1x1, 2x2, 3x3 ? because the object if is like a list you can use a UITableView. – Ladd.c Sep 29 '19 at 00:47
  • @Ladd.c. I can't use UITableView for my purpose actually. I am using UICollectionView which is inside UIContainerView. – Akhil Sep 30 '19 at 09:58
  • Now i got my doubt like usually the UI hangs when there is timeout error or some kind of error received from AdMob – Akhil Sep 30 '19 at 10:01
  • Where is this method 'preloadNextGoogleBannerAd' called? I think the problem is with the dispatch_async called from some UICollectionView method because I had similar problems – Ladd.c Sep 30 '19 at 16:08
  • First i call "preloadNextGoogleBannerAd" after i get data from server, then when i receive the AdView in "adViewDidReceiveAd:(GADBannerView *)adView" this method – Akhil Sep 30 '19 at 17:06
  • @Ladd.c Even after i removed dispatch_async no use, I am doing this one after the another, so when it come to end of the list. it give an error "Request Error: The Google Ad request was unable to be fulfilled before a timeout occurred". after i get this error , UICollectionView cant scroll smoothly. Do you know how to handle this ? – Akhil Oct 01 '19 at 06:48
  • @Akhil : Is it possible display different Ads on each recurring items? – Priya Jun 22 '20 at 01:18
  • 1
    @Priya :Yes its possible. – Akhil Jun 23 '20 at 10:11
  • @Akhil: Please post your answer if possible here. I am getting same Ads in each recurring items. https://stackoverflow.com/questions/62485567/ios-swift-google-addmob-sdk-how-to-display-different-ads-in-recurring-items-in – Priya Jun 25 '20 at 07:04

0 Answers0