iAd插页式广告没有一致显示?在模拟器上完全没有

时间:2015-08-03 07:06:22

标签: ios swift iad

iAd插页式广告在iPhone模拟器上根本没有出现,而且它们在我的iPhone上不会一直显示。我已进入开发者设置,将填充率更改为100%,并启用了无限广告演示。没有区别......插页式广告通常会在第一次出现时显示出来,然后在几分钟到十五分钟的时间内再次展示。不知道造成时间差异的原因。

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

谢谢!

1 个答案:

答案 0 :(得分:2)

因此,似乎只有在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()
    }