ratson / cordova-plugin-admob-free

New development has been moved to "admob-plus-cordova", https://github.com/admob-plus/admob-plus/tree/master/packages/cordova
https://github.com/admob-plus/admob-plus
MIT License
499 stars 214 forks source link

[iOS] Interstitial top position wrong after upgrade to WKWebView #451

Closed rafaellop closed 3 years ago

rafaellop commented 3 years ago

@tennist I've noticed you committed some changes and fixes to the iOS version of the plugin so I think you are the right person to ask for help. I've got issues with the interstitial ads positions which are incorrectly displayed on different iOS devices. Here's a screenshot out of a simulator (iPhone SE), but the same behavior but different offset for the top of interstitials occurs across on other simulators and the issue happens on real hardware as well.

I'm testing on the latest XCode, the latest plugin and the 7.64 AdMob SDK, Cordova 10 and Cordova iOS 6.1.0. The issue started to happen when I upgraded from UIWebView to the WKWebView. Banner position is OK. Just the interstitials are moved down for some value but I see no placement code in the CDVAdMob.m

sas

rafaellop commented 3 years ago

OK, I've found the reason and I'm very surprised this is not handled by the AdMob framework itself. The default modal presentation style has changed since iOS 13 to page sheet, not full screen. The header documentation for modalPresentationStyle says:

Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.

So it seems there should be enough to set the style before an interstitial is shown. So I did that but this changes nothing. As I said I'm not an iOS developer and I'm not sure if such a change would be enough, but it seems right to me. However it doesn't help. Maybe someone could help to sort that out?

Here's my change to the CDVAdMob.m which should do but it's not:

(BOOL) __showInterstitial:(BOOL)show {
    NSLog(@"__showInterstitial");

    if (!self.interstitialView){
        [self __cycleInterstitial];
    }

    [self.viewController setModalPresentationStyle:UIModalPresentationFullScreen]; // **added**
    [self.viewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; // **added**

    if (self.interstitialView && self.interstitialView.isReady) {
        [self.interstitialView presentFromRootViewController:self.viewController];
        return true;
    } else {
        NSLog(@"Ad wasn't ready");
        return false;
    }
}

I've added two new lines with the // added comment but no change. Interstitial is still not full screen as in the screenshot above.

rafaellop commented 3 years ago

It seems that the AdMob SDK was not updated properly to 7.64. After checking that the interstitial is full screen again. Sorry for bothering.