NativeScript / firebase

Modular Firebase 🔥 implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
https://docs.nativescript.org/plugins/firebase-core.html
Apache License 2.0
52 stars 46 forks source link

AdMob iOS rootViewController issues #137

Closed LewisSmallwood closed 1 year ago

LewisSmallwood commented 1 year ago

Hi there,

I am having a few issues with AdMob on iOS. Specifically, when instantiating an Interstitial Ad. It preloads successfully, but upon calling the show method, this seems to always throw the error:

{
    event: "adFailedToShowFullScreen",
    error: "Content Error: Cannot present from a nil view controller.",
    data: {}
}

This is being raised by the delegate: GADFullScreenContentDelegateImpl.prototype.adDidFailToPresentFullScreenContentWithError.

Any help would be greatly appreciated. Thanks.

LewisSmallwood commented 1 year ago

For reference, I have found where this problem is occurring.

When calling topViewController() within the show() method of the InterstitialAd class (in index.ios), the top view controller is coming back as undefined.

I will try and put a fix in place, and open a PR.

Screenshot 2022-10-04 at 15 46 15 Screenshot 2022-10-04 at 15 46 31
aymenelhajayed commented 1 year ago

Me too i have an issue with AdMob on iOS, with the normal banner. Its preloaded but when calling the methods to show the ad the application throw this error in simulator and kill the app in Testflight. Ad failed to load: Error: You must set the rootViewController property of <GADInternalBannerView: 0x7faba07267e0; frame = (0 0; 414 100); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x600001fc8a40>> before loading a request. Any one encounter the same or similar bug with Firebase/admob ? Thanks !

LewisSmallwood commented 1 year ago

@aymenelhajayed I've just had a look at the code. The banner view uses the same method to get the rootViewController as the Interstitial Ad, so this PR should fix the issue 🤞🏼

aymenelhajayed commented 1 year ago

Thanks you @LewisSmallwood this solution solve the first problem, but now i have a new one : CONSOLE LOG: Ad failed to load: Error: Request Error: No ad to show. And are you using a normal banner here ?

LewisSmallwood commented 1 year ago

@aymenelhajayed once the npm package has been updated, I believe this problem should resolve itself.

I experienced it previously when trying to use an adaptive banner size. The width/height of the rootViewController couldn't be determined so Google returns "No ad to show" as it can't find any adverts to fill in 0x0 pixels.

Alternatively, if this doesn't fix that issue, the guidance on this StackOverflow link might be of help. https://stackoverflow.com/questions/39108558/admob-bannerview-request-error-no-ad-to-show