简体   繁体   English

Admob 插页式广告使 iPhone 变得疯狂热和应用程序滞后和崩溃

[英]iPhone getting crazy hot and app lagging and crashing with Admob interstitial ads

I have some serious issued when it comes to my Admob implementation.当涉及到我的 Admob 实现时,我有一些严重的问题。 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.我 100% 确定这是由于显示了很多 Admob 插页式广告。 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?在我看来,memory 在显示大量插页式广告后会超载,有没有办法在显示后处理它们?

You need clear old interstitial before new request:您需要在新请求之前清除旧的interstitial

- (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;
    }];
}

Probably it's related to increasing WKWebView instances in the memory?可能与增加 memory 中的 WKWebView 实例有关? I've come across the similar bizarre Google Ad Manager native ad behaviour.我遇到过类似的奇怪的 Google Ad Manager 原生广告行为。 There're the details: https://issuetracker.google.com/issues/198511570有详细信息: https://issuetracker.google.com/issues/198511570

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM