Home > Software design >  iPhone getting crazy hot and app lagging and crashing with Admob interstitial ads
iPhone getting crazy hot and app lagging and crashing with Admob interstitial ads

Time:12-21

I have some serious issued when it comes to my Admob implementation. I have followed official docs, but after a while playing my game the phone starts to get really hot, and a while after that the app suddenly gets really slow and laggy, before eventually crashing.

I am 100% sure it is due to a lot of Admob interstitial ads displaying. Since the app functions perfectly without them.

I will admit there is quite a lot of ads showing if you play for a while, but turning them off is not an option since it the main source of income on the app.

This is the code I use to load and display the ads:

- (void)loadInterstitial {
    [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-xxx/xxx" request:[GADRequest request] completionHandler:^(GADInterstitialAd *ad, NSError *error) {
        if (error) {
            NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
            return;
        }
        self.interstitial.fullScreenContentDelegate = nil;
        self.interstitial = ad;
        self.interstitial.fullScreenContentDelegate = self;
    }];
}

- (void)displayInterstitial {
    if (self.interstitial) {
        [self.interstitial presentFromRootViewController:self];
        adCount = 0;
        [[NSUserDefaults standardUserDefaults] setInteger:adCount forKey:@"adCount"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    } else {
        NSLog(@"Ad wasn't ready");
    }
}

- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
    [self loadInterstitial];
}

Nothing special. To me it seems like the memory gets overloaded after showing a large number of interstitial ads, is there some way of disposing them after displaying them?

CodePudding user response:

You need clear old interstitial before new request:

- (void)loadInterstitial {
    self.interstitial.fullScreenContentDelegate = nil;
    self.interstitial = nil;
    [GADInterstitialAd loadWithAdUnitID:@"ca-app-pub-xxx/xxx" request:[GADRequest request] completionHandler:^(GADInterstitialAd *ad, NSError *error) {
        if (error) {
            NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
            return;
        }
        self.interstitial = ad;
        self.interstitial.fullScreenContentDelegate = self;
    }];
}

CodePudding user response:

Probably it's related to increasing WKWebView instances in the memory? I've come across the similar bizarre Google Ad Manager native ad behaviour. There're the details: https://issuetracker.google.com/issues/198511570

  • Related