googleads / googleads-mobile-ios-examples

googleads-mobile-ios
Apache License 2.0
943 stars 805 forks source link

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

Open lotz opened 1 month ago

lotz commented 1 month ago

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 commented 1 month ago

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:

lotz commented 1 month ago

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

abinhho commented 1 month ago

Same here.

dylancom commented 3 weeks ago

@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?

lotz commented 3 weeks ago

Calling load with the existing instance works for me.