插页广告没有持续显示?而在模拟器上完全不是这样

  • 本文关键字:模拟器 显示 ios swift iad
  • 更新时间 :
  • 英文 :


iAd的插页广告在iPhone模拟器上根本无法显示,在我的iPhone上也无法持续显示。我打开了开发者设置,将填充率更改为100%,并打开了无限广告呈现。没有区别……插页广告通常会在第一次出现时出现,然后在几分钟到15分钟内不会再次出现。不知道是什么原因造成了时间上的差异。

此外,似乎没有一种方法来跟踪插页广告是否会显示或不显示/如果它实际上显示或没有。我知道有一个间隙委托,但似乎不再使用了。我使用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()
    }

最新更新