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

问题描述

我有一个 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 {$0.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. 在调用 show(from:) 后调用了 loadAd()

关闭按钮现在会根据需要显示。