当应用进入后台时暂停和恢复 Google Admob Banner 广告目标 c

Akh*_*hil 6 objective-c admob ios mobile-ad-mediation

我在我的 iOS 应用程序中使用带有广告中介的 Google Admobs。似乎存在电池耗尽问题,因为即使应用程序在后台运行,谷歌广告也在运行。当应用程序进入后台并在应用程序激活时恢复时,我需要做些什么来暂停谷歌广告。提前致谢。

use*_*465 4

我找到了一个对我来说效果好坏参半的解决方案。希望有人能提供更可靠的解决方案。在 AppDelegate.m 中我有这个...

\n
- (void)applicationDidEnterBackground:(UIApplication *)application\xc2\xa0{\n\xc2\xa0 \xc2\xa0 [self.viewController.bannerView removeFromSuperview];\n\xc2\xa0 \xc2\xa0 self.viewController.bannerView.delegate = nil;\n}\n\n- (void)applicationWillEnterForeground:(UIApplication *)application\xc2\xa0{\n\xc2\xa0 \xc2\xa0 \xc2\xa0[self.viewController loadAdBanner];\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这适用于我的一个应用程序。如果我只是调用removeFromSuperview并且不将bannerView的委托设置为nil,当我查看手机上的电池使用情况(运行iOS 13.5.1)时,我仍然会看到我的应用程序的后台活动。我有另一个应用程序,我在做基本上相同的事情,但无论如何我仍然看到后台活动。在这两种情况下,我都使用 AdMob 7.61.0。

\n

我的bannerView声明如下:

\n
@property(nonatomic, strong) GADBannerView *bannerView;\n
Run Code Online (Sandbox Code Playgroud)\n

在 MyViewController.m 中,我有一个 loadAdBanner 函数,看起来像这样......

\n
- (void)loadAdBanner {\n    ...\n    [self.bannerView setDelegate:self];\n    self.bannerView.rootViewController = self;\n    [self.view addSubview:self.bannerView];\n    GADRequest *request = [GADRequest request];\n    [self.bannerView loadRequest:request];\n    ...\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我希望这有帮助。

\n