googleads-mobile-ios-examples icon indicating copy to clipboard operation
googleads-mobile-ios-examples copied to clipboard

Banner ad blank when app returns to foreground sometimes (iOS)

Open lotz opened this issue 1 year ago • 12 comments

I have some iOS apps that implements a banner ad using UIKit. I implement the “GADBannerViewDelegate” protocol to listen for ad loading events and errors.

Occasionally, when opening the app, returning to the Home Screen on iOS, then returning to the app after some time has passed (possibly enough time for the app to be “suspended” by the OS), the ad banner is blank.

After some view hierarchy debugging, I’ve noticed that the banner ad view utilizes a WKWebView to render the ad from a URL. When the ad is blank, it appears that this WKWebView’s “url” property is “nil”. Additionally, the GADBannerViewDelegate’s error method is not called, so I don’t know when this has occurred to recover from it.

I think this is a bug as it seems to have started happening recently, maybe within the last few months. I have been using Google Mobile Ads in my iOS apps for over 10 years. Any help would be appreciated.

Additionally, I ran the AdMob “BannerExample” project from this repo, installing the latest version of Google Mobile Ads for iOS SDK from Swift Package Manager (11.3.0 at the time of this post), and the issue is present there on iOS 17.4.

IMG_0951

lotz avatar May 06 '24 01:05 lotz

The only change I have made to the example project is adding the latest version of the Google Mobile Ads SDK via Swift Package Manager (11.3.0). The ad unit ID and other IDs come directly from the project.

This issue only surfaces on an actual device after some time has passed, enough that the OS puts the app into a “suspended” state. Maybe 30 mins or so, or an hour, depending on usage of the device and other apps (seems somewhat consistent overnight if you open the app just before bed). While it can be challenging to reproduce on demand, as there’s no way to force the “suspended” state, it happens frequently enough with my own apps that I noticed the issue based on normal usage patterns (opening the apps at regular intervals throughout the day).

I have also posted this issue in the following forums:

  • https://support.google.com/admob/thread/272825691/banner-ad-blank-when-app-returns-to-foreground-sometimes-ios?hl=en&authuser=1
  • https://groups.google.com/u/1/g/google-admob-ads-sdk/c/rwBpqOUr8m8

lotz avatar May 06 '24 10:05 lotz

I've created a smaller example project here as well: https://github.com/lotz/googleads-mobile-ios-example-bug

lotz avatar May 08 '24 23:05 lotz

Same here.

abinhho avatar May 15 '24 03:05 abinhho

@lotz to fix this, is it enough to call loadRequest(objc)/load(swift) upon foregrounding or do we need to create a complete new instance?

dylancom avatar May 21 '24 09:05 dylancom

Calling load with the existing instance works for me.

lotz avatar May 21 '24 10:05 lotz

@lotz

I was not able to replicate this on my end. Can you open a SDK support case and include the debug log and a network trace?

https://developers.devsite.corp.google.com/admob/support

NVentimiglia avatar Jul 17 '24 17:07 NVentimiglia

@NVentimiglia I have already opened a discussion here with a lengthy debug process: https://groups.google.com/u/1/g/google-admob-ads-sdk/c/rwBpqOUr8m8

Reproducing this on demand is difficult, as there is no way to manually trigger the "suspended" state -- it must happen on its on after several hours or even overnight.

lotz avatar Jul 17 '24 17:07 lotz

@lotz

Thanks for your patience, I was able to confirm the issue and confirm that we are working on a solution.

NVentimiglia avatar Jul 17 '24 20:07 NVentimiglia

@NVentimiglia this is great to hear, thanks for the update!

lotz avatar Jul 17 '24 23:07 lotz

Hey @NVentimiglia, when do you think we can expect a resolution for this bug? 👀

mschonvogel avatar Sep 03 '24 11:09 mschonvogel

Any updates on this topic, @NVentimiglia? :slightly_smiling_face:

JulianMaus98 avatar Sep 06 '24 12:09 JulianMaus98

From the google thread :

Back to this issue, the OS reserves the right to terminate WKWebView at any time due to memory pressure. That could be the underlying problem. And for that we don't have a way to control. None of the current BannerViewDelegate methods are appropriate for this event, so it's expected none is invoked. We are exploring if we should provide a new delegate method to listen to web view termination for better user experience, but that's still too early to say. Right now your best option would be to stay on GMA v10 and above, and requesting a new ad when the app is foregrounded.

I will forward this to engineering to see if there is something we can do such as an error event.

That said, In the mean time I recommend reloading banners if the app is suspended.

NVentimiglia avatar Oct 01 '24 22:10 NVentimiglia