iAd Interstitials 显示不一致?根本不在模拟器上

iAd Interstitials not showing consistently? And not at all on the simulator

iAd 插页式广告根本没有出现在 iPhone 模拟器上,它们也没有始终如一地出现在我的 iPhone 上。我已经转到开发人员设置,将填充率更改为 100%,并打开无限广告展示。没什么区别……插页式广告通常会在它应该显示的第一时间显示,然后在几分钟到十五分钟内不会再次显示。不知道是什么导致了时间差异。

此外,似乎没有办法跟踪插页式广告是否会显示/是否实际显示。我意识到有一个插页式代表,但似乎不再使用了。我调用插页式广告的方式是使用 viewController.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Automatic

谢谢!

因此,使用 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()
    }