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?
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;
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With