小编典典

iAd插页式广告不能始终显示?而且根本不在模拟器上

swift

iAd插页式广告完全没有显示在iPhone模拟器上,并且也没有始终显示在我的iPhone上。我进入了“开发人员”设置,将填充率更改为100%,然后启用了“无限广告展示”。没什么…插页式广告通常会在第一个显示时间,然后几分钟到十五分钟都不会显示。不知道是什么造成时间差异。

此外,似乎还没有一种方法可以跟踪插页式广告是否显示/是否实际显示或不显示。我意识到有一个非页内广告代表,但似乎已不再使用。我称呼非页内广告的方式是使用viewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic

谢谢!


阅读 336

收藏
2020-07-07

共1个答案

小编典典

因此看来using
requestInterstitialAdPresentation仅打算在ADInterstitialPresentationPolicy设置为时使用Automatic。使用实施插页式广告时,您Manual
ADInterstitialPresentationPolicy必须presentInView按自己的时间间隔展示广告。以这种方式展示插页式广告时,它不会加载自己的关闭按钮来关闭自己。因此,我所做的是创建一个,UIView以展示插页式广告,并使用插页式广告委托方法关闭UIView。测试时仍然会出现与从iAd网络接收广告不一致的情况。有时您会收到一个广告,有时无法加载,这使我们可以请求一个新广告,有时则什么也没有发生。这似乎只是iAd插页式广告的本质。

import UIKit
import iAd // Import iAd

class ViewController: UIViewController, ADInterstitialAdDelegate { // Include the delegate

    var iAdInterstitial = ADInterstitialAd() // Our ad
    var iAdInterstitialView = UIView() // View to present our ad in
    var adLoaded = false // Bool to keep track if an ad is loaded or not

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

    func setupAd() {
        // Set presentation to manual so we can choose when to present the interstitial
        // Setting this will also fetch an interstitial ad for us
        self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Manual
        iAdInterstitial.delegate = self // Set the delegate

        // Make our view the same size as the view we will be presenting in
        iAdInterstitialView.frame = self.view.bounds
    }

    func requestNewAd() {
        // This will fetch an ad for us
        ViewController.prepareInterstitialAds()
        println("Requesting new ad")
    }

    @IBAction func presentAdButton(sender: AnyObject) {
        if (adLoaded) {
            // We have an ad that is loaded so lets present it
            self.view.addSubview(iAdInterstitialView)
            iAdInterstitial.presentInView(iAdInterstitialView)
        }
        else {
            // No ad has been loaded
            println("Ad not loaded")
        }
    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
        // Kinda works as expected
        // Sometimes is called prematurely
        // Sometimes takes minutes after ad is dismissed to be called
        println("interstitialAdDidUnload")

        // Get new ad
        adLoaded = false
        iAdInterstitialView.removeFromSuperview()
        requestNewAd()
    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        // Failed to load ad so lets try again
        println("didFailWithError: \(error)")
        requestNewAd()
    }

    func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
        // There is an ad and it has begun to download
        println("interstitialAdWillLoad")
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        // We got an ad
        println("interstitialAdDidLoad")
        adLoaded = true
    }

    func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
        println("interstitialAdActionShouldBegin")
        return true;
    }

    func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
        // Done with this ad. Lets get a new one
        println("interstitialAdActionDidFinish")
        iAdInterstitialView.removeFromSuperview()
        adLoaded = false
        requestNewAd()
    }
2020-07-07