iAd插页式广告不适用于精灵工具包应用Xcode swift

时间:2015-08-08 22:09:28

标签: ios xcode swift sprite-kit iad

我正试图在我的spriteKit游戏中使用iAd实施插页式广告。我的代码如下:

class ViewController: UIViewController, ADInterstitialAdDelegate {

var interAd = ADInterstitialAd()
var interAdView: 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)
}

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!.frame
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()

}

这段代码给我的问题多于结果。不幸的是,我是一个在应用程序中实现任何类型的广告的初学者,我不知道如何改变这些对我有利。

我得到的一个问题是输出跟踪ad did load(因为您可以看到广告出现时应该跟踪的内容)但是当跟踪ad did load时,不会显示广告。我等了至少3分钟但没有任何反应。

我遇到的另一个问题是WARNING: More than 10 instances of ADBannerView or ADInterstitialView currently exist. This is a misuse of the iAd API, and ad performance will suffer as a result. This message is printed only once.,但在加载广告的功能被调用一次或两次后会打印出来。

0 个答案:

没有答案