繁体   English   中英

在 iOS 13 Xcode 11 中全屏展示插页式广告

[英]Presenting interstitial ad in fullscreen in iOS 13 Xcode 11

我刚刚将我的 Xcode 更新为 11 并尝试在 iOS 13 设备上运行我的应用程序。 我发现视图控制器没有全屏显示,但我可以用这个问题解决这个问题: Presting modal in iOS 13 fullscreen

但我也有一个问题,即 Admob 插页式广告没有全屏显示。 我将附上一个截图来演示,你会看到顶部不在顶部。

这就是我展示插页式广告的方式:

if (self.interstitial.isReady) {

    [self.interstitial presentFromRootViewController:self];

}

在此处输入图像描述

将演示模式更改为:

抱歉,我写在 Swift 中,虽然这在 Objective-C 中应该是相似的。

viewController.modalPresentationStyle = .fullScreen

或者

viewController.modalPresentationStyle = .overFullScreen

在 iOS 13 我注意到默认modalPresentationStyle.overCurrentContext.currentContext ,这会产生奇怪的 animation 并最小化呈现视图 Z594C103F2C6E0310C3D8ABE059C 的框架

我认为有一个简单的解决方案,您需要更新 Google Mobile Ads SDK(pod 更新或 carthage 更新)。 广告 SDK:7.50.0,正式发布 iOS 13 支持。

这是插页式广告的基本助手 class ,它不依赖于我的任何视图或模式实现。 它只会在 rootViewController 上显示广告,即使在横向模式下也可以为我工作,这也可用于 SwiftUI。 如果你还没有,试试这个。

import Foundation
import GoogleMobileAds
import UIKit
    
final class InterstitialAd : NSObject, GADInterstitialDelegate {
    var interstitial: GADInterstitial? = nil
    
    func LoadInterstitial() {
        interstitial = GADInterstitial(adUnitID: Constants.interstitialAdCode)
        let req = GADRequest()
        interstitial!.load(req)
        interstitial!.delegate = self
    }
    
    func showAd() {
        if let ad = self.interstitial, ad.isReady {
           let root = UIApplication.shared.windows.first?.rootViewController
           ad.present(fromRootViewController: root!)
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM