iOS 的 MoPub:未显示间隙关闭按钮

MoPub for iOS: Interstitial close button not showing

我有一个 SwiftUI/SpriteKit 项目,我正在尝试使用找到的测试广告 ID here.

实施 MoPub 插页式广告

广告按预期加载,点击广告成功,但广告上没有关闭按钮。

我已经通过 CocoaPods 集成了 MoPub SDK,如下所示:

pod 'mopub-ios-sdk'

我正在 AppDelegateapplication(_:didFinishLaunchingWithOptions:) 函数中初始化 MoPub SDK,如下所示:

let sdkConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: "MyIdHere")

sdkConfig.loggingLevel = .debug

MoPub.sharedInstance().initializeSdk(with: sdkConfig, completion: {
  DispatchQueue.main.async {
     //The SDK is initialized.
  }
})

我通过下面的 showAd 函数展示广告:

class InterstitialAds: UIViewController, MPAdViewDelegate, MPInterstitialAdControllerDelegate {
    var moPubView: MPAdView?
    
    func viewControllerForPresentingModalView() -> UIViewController! {
        return self
    }
    
    
    func interstitialDidLoadAd(_ interstitial: MPInterstitialAdController) {
        
    }
    func interstitialDidFail(toLoadAd: MPInterstitialAdController, withError: Error){
        
    }
    func interstitialWillDismiss(_ interstitial: MPInterstitialAdController) {
        
    }
    func interstitialDidDismiss(_ interstitial: MPInterstitialAdController) {
        
    }
    func interstitialDidExpire(_ interstitial: MPInterstitialAdController) {
        
    }
    
    
    func showAd() {
        let topViewController = UIApplication.shared.windows.filter {[=13=].isKeyWindow}.first?.rootViewController
        
        self.modalPresentationStyle = .fullScreen
        
        topViewController?.present(self, animated: true) {
            let adId = "4f117153f5c24fa6a3a92b818a5eb630" //Test ad unit id

            self.moPubView = MPAdView.init(adUnitId: adId)

            let bounds = self.view.bounds
            var adFrame = CGRect.zero
            adFrame.size = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

            if let v = self.moPubView {
                v.frame = adFrame
                v.maxAdSize = kMPPresetMaxAdSizeMatchFrame
                v.delegate = self
                self.view.addSubview(v)
                v.loadAd()
            }
        }
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
}

问题: 我需要进行哪些更改才能显示关闭按钮?

谢谢!

我通过进行一些更改设法使它正常工作:

  1. 已将 MPAdView 替换为 MPInterstitialAdController
  2. 已将 MPAdView.init(adUnitId: adId) 替换为 MPInterstitialAdController(forAdUnitId: adId)
  3. 在调用 loadAd()
  4. 之后调用了 show(from:)

关闭按钮现在按需要显示。