iAd的插页式广告无法快速运行

iAd的插页式广告无法快速运行

本文介绍了iAd的插页式广告无法快速运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试插入非页内广告,但是我的代码似乎无法正常工作.

I'm trying to implement interstitial ads however my code doesn't seem to work.

class ViewController: UIViewController, ADInterstitialAdDelegate {

var interAd = ADInterstitialAd()
var interAdView: UIView = UIView()
var closeButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton

override func viewDidAppear(animated: Bool) {

closeButton.frame = CGRectMake(10, 10, 20, 20)
    closeButton.layer.cornerRadius = 10
    closeButton.setTitle("x", forState: .Normal)
    closeButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
    closeButton.backgroundColor = UIColor.whiteColor()
    closeButton.layer.borderColor = UIColor.blackColor().CGColor
    closeButton.layer.borderWidth = 1
    closeButton.addTarget(self, action: "close:", forControlEvents: UIControlEvents.TouchDown)
loadAd()
}
func close(sender: UIButton) {
    closeButton.removeFromSuperview()
    interAdView.removeFromSuperview()
}
func loadAd() {
    println("load ad")
    interAd = ADInterstitialAd()
    interAd.delegate = self
}

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    println("ad did load")

    interAdView = UIView()
    interAdView.frame = self.view.bounds
    view.addSubview(interAdView)

    interAd.presentInView(interAdView)
    UIViewController.prepareInterstitialAds()

    interAdView.addSubview(closeButton)
}

func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {

}

func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
    println("failed to receive")
    println(error.localizedDescription)

    closeButton.removeFromSuperview()
    interAdView.removeFromSuperview()

}
}

广告未显示,由于某种原因,该应用甚至跟踪广告确实已加载",但该广告未显示.有时,我会得到一个错误,即xCode告诉我一次显示了10个以上的广告实例,但是我什至都没有看到一个广告.可能是什么问题?如果有人可以告诉我在关卡结束后如何显示广告,那还是一个加号,但是如果您不能全部令人满意的话.谢谢您的帮助!

ads aren't showing up, for some reason the app is even tracing "ad did load" but the ad doesn't show up. Sometimes I get the error where xCode tells me that more than 10 instances of ads are being shown at once, yet I haven't been presented with even one ad. What could be the issue? Also it'd be a plus if somebody can tell me how I can make the ad show up after the level ends, but if you can't its all good. Thank you for your help!

推荐答案

我创建了一个新的SKScene并将其添加到文件中:

I created a new SKScene and added this into the file:

class Advertisement11: SKScene, ADInterstitialAdDelegate {
    var interAd = ADInterstitialAd()
    var interAdView = UIView()
    var closeButton = UIButton()
    var returnToScene = SKScene()

    override func didMoveToView(view: SKView) {
        closeButton.frame = CGRectMake(20, 20, 30, 30)
        closeButton.layer.cornerRadius = 15
        closeButton.setTitle("x", forState: .Normal)
        closeButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
        closeButton.backgroundColor = UIColor.whiteColor()
        closeButton.layer.borderColor = UIColor.blackColor().CGColor
        closeButton.layer.borderWidth = 1
        closeButton.addTarget(self, action: "close:", forControlEvents: UIControlEvents.TouchDown)
        loadAd()
    }

    func close(sender: UIButton) {
        closeButton.removeFromSuperview()
        interAdView.removeFromSuperview()
        let block = SKAction.runBlock {
            self.view?.presentScene(self.returnToScene)
        }
        self.runAction(block)//this is to go back to the previous Scene
    }

    func loadAd() {
        print("load ad")
        interAd = ADInterstitialAd()
        interAd.delegate = self
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        print("ad did load")

        interAdView = UIView()
        interAdView.frame = self.view!.frame
        view!.addSubview(interAdView)

        interAd.presentInView(interAdView)
        UIViewController.prepareInterstitialAds()

        interAdView.addSubview(closeButton)
    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {

    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        print("failed to receive")
        print(error.localizedDescription)

        closeButton.removeFromSuperview()
    //  interAdView.removeFromSuperview()
    }
}

这篇关于iAd的插页式广告无法快速运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:25