Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause and Resume Google Admob Banner ads when app enters background Objective c

I am using Google Admobs with ad mediations in my iOS application. It seems like there is battery draining issue because google ads are running even when app is in background. Is there something that i have to do to Pause google Ads when app enters background and resume when app become active. Thanks in advance.

like image 818
Akhil Avatar asked Jun 03 '20 19:06

Akhil


People also ask

How do I pause an AdMob ad?

Find the ad you want to change and click the drop-down next to the status icon. Change the status: Enabled: Selecting this status will enable the ad to be served. Paused: Selecting this status will pause this ad and it won't be served until you enable it.

How do I avoid invalid clicks in AdMob?

Use test ads to avoid generating invalid clicks. It is important to enable test ads during development so that you can click on them without charging Google advertisers. If you click on too many ads without being in test mode, your account can be flagged for invalid activity.

Can AdMob work without uploading at Play Store?

You can definitely use Admob without uploading your app to Google Play.

Why is AdMob not showing ads in my app?

Ads won't show if you haven't integrated the Google Mobile Ads SDK correctly. Is your ad implementation code working properly? Test your implementation code to check that ads can show. You can also use ad inspector to test your app's ad serving.


1 Answers

I have found a solution that has had mixed success for me. Hopefully someone can provide a more reliable solution. In AppDelegate.m I have this...

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [self.viewController.bannerView removeFromSuperview];
    self.viewController.bannerView.delegate = nil;
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
     [self.viewController loadAdBanner];
}

This works for one of my apps. If I just call removeFromSuperview and don't set the delegate for the bannerView to nil, I still see background activity for my app when I look in the battery usage on my phone (running iOS 13.5.1). I have another app where I am doing basically the same thing but I still see background activity regardless. In both cases I am using AdMob 7.61.0.

My bannerView is declared like this:

@property(nonatomic, strong) GADBannerView *bannerView;

In MyViewController.m I have a loadAdBanner function that looks something like this...

- (void)loadAdBanner {
    ...
    [self.bannerView setDelegate:self];
    self.bannerView.rootViewController = self;
    [self.view addSubview:self.bannerView];
    GADRequest *request = [GADRequest request];
    [self.bannerView loadRequest:request];
    ...
}

I hope this helps.

like image 189
user1248465 Avatar answered Oct 12 '22 20:10

user1248465